-
Notifications
You must be signed in to change notification settings - Fork 19
/
TargetData.java
97 lines (83 loc) · 2.52 KB
/
TargetData.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.sql.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class TargetData
{
public static String createTable(Connection conn, String targetTable, String sourceConfig, String sql) throws SQLException
{
try
{
String tableName = "";
String columns = "";
Integer myPort = Listener.getPort(conn);
if (GPLink.debug)
System.out.println("Port: " + myPort);
Properties prop = new Properties();
InputStream inputStream = new FileInputStream(targetTable);
if (inputStream != null)
{
prop.load(inputStream);
}
else
{
throw new FileNotFoundException(targetTable + " not found!");
}
tableName = prop.getProperty("tableName");
columns= prop.getProperty("columns");
Validation.checkProperty("tableName", tableName);
Validation.checkProperty("columns", columns);
String strSQL = "DROP EXTERNAL TABLE IF EXISTS " + tableName + ";";
if (GPLink.debug)
System.out.println(strSQL);
Statement stmt = conn.createStatement();
stmt.executeUpdate(strSQL);
strSQL = "CREATE EXTERNAL TABLE " + tableName + "\n";
strSQL += "(" + columns + ")\n";
strSQL += "LOCATION ('gpfdist://" + GPLink.gplinkHostName + ":" + myPort + "/" + sourceConfig + "+" + sql + "#transform=gplink')\n";
strSQL += "FORMAT 'TEXT' (delimiter '|' null 'null');";
if (GPLink.debug)
System.out.println(strSQL);
stmt.executeUpdate(strSQL);
return tableName;
}
catch (IOException iex)
{
throw new SQLException(iex.getMessage());
}
catch (SQLException ex)
{
String exceptionMessage = ex.getMessage();
SQLException nextException = ex.getNextException();
while (nextException != null)
{
exceptionMessage = exceptionMessage + " " + nextException.getMessage();
nextException = nextException.getNextException();
}
throw new SQLException(exceptionMessage);
}
}
public static void dropTable(Connection conn, String tableName) throws SQLException
{
try
{
String strSQL = "DROP EXTERNAL TABLE IF EXISTS " + tableName + ";";
if (GPLink.debug)
System.out.println(strSQL);
Statement stmt = conn.createStatement();
stmt.executeUpdate(strSQL);
}
catch (SQLException ex)
{
String exceptionMessage = ex.getMessage();
SQLException nextException = ex.getNextException();
while (nextException != null)
{
exceptionMessage = exceptionMessage + " " + nextException.getMessage();
nextException = nextException.getNextException();
}
throw new SQLException(exceptionMessage);
}
}
}