-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyzeCreate.java
70 lines (63 loc) · 2.58 KB
/
AnalyzeCreate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
import java.io.*;
import gudusoft.gsqlparser.nodes.TColumnDefinition;
import gudusoft.gsqlparser.stmt.*;
public class AnalyzeCreate {
protected static void analyzeCreateTableStmt(TCreateTableSqlStatement pStmt)
{
String table_name=pStmt.getTargetTable().toString();
ArrayList<String> col=new ArrayList<String>();
if(!Main_file.table.containsKey(table_name))
{
try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("metadata.txt", true))))
{
out.println("<begin_table>");
out.println(table_name);
// System.out.println("Table Name:"+table_name);
// System.out.println("Columns:");
TColumnDefinition column;
for(int i=0;i<pStmt.getColumnList().size();i++)
{
column = pStmt.getColumnList().getColumn(i);
col.add(column.getColumnName().toString());
out.println(column.getColumnName().toString());
// System.out.println("\tname:"+column.getColumnName().toString());
// System.out.println("\tdatetype:"+column.getDatatype().toString());
//
// System.out.println("");
}
Main_file.table.put(table_name, col);
for(String next:col)
{
Map<String,ArrayList<Integer>> lmap=new HashMap<String,ArrayList<Integer>>();
ArrayList<Integer> l=new ArrayList<Integer>();
lmap.put(next, l);
if(Main_file.data.get(table_name)==null)
{
Main_file.data.put(table_name,lmap);
}
if(!Main_file.data.get(table_name).containsKey(next))
{
Main_file.data.get(table_name).put(next,l);
}
}
// System.out.println("Afet create statement");
// System.out.println(Main_file.data);
// System.out.println(Main_file.table);
out.println("<end_table>");
out.close();
File file = new File(table_name+".csv");
if (!file.exists()) {
file.createNewFile();
}
// System.out.println("File Created");
}catch (IOException e) {
//exception handling left as an exercise for the reader
System.out.println("ERROR!!!");
//System.out.println(e.printStackTrace());
}
}
else
System.out.println("ERROR:TAble Already Exist!!!");
}
}