From 7831212dbc11953976450f0569045bd11b27ead2 Mon Sep 17 00:00:00 2001 From: Jaehwa Jung Date: Fri, 24 Oct 2014 10:02:22 +0900 Subject: [PATCH 1/3] TAJO-1119: JDBC driver should support TIMESTAMP type. --- .../org/apache/tajo/client/ResultSetUtil.java | 4 ++ .../org/apache/tajo/jdbc/TestTajoJdbc.java | 43 +++++++++++++++++++ .../org/apache/tajo/jdbc/MetaDataTuple.java | 4 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java index 056eb2c05e..ad600a52a3 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java @@ -75,6 +75,8 @@ public static String toSqlType(TajoDataTypes.DataType type) { return "character"; case DATE: return "date"; + case TIMESTAMP: + return "timestamp"; case VARCHAR: return "varchar"; case TEXT: @@ -103,6 +105,8 @@ public static int tajoTypeToSqlType(TajoDataTypes.DataType type) throws SQLExcep case NUMERIC: return Types.NUMERIC; case DATE: + return Types.DATE; + case TIMESTAMP: return Types.TIMESTAMP; case VARCHAR: return Types.VARCHAR; diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java index e477939b98..7bcca5eaf4 100644 --- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java +++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java @@ -487,4 +487,47 @@ public void testSetPreparedStatement() throws Exception { } } } + + @Test + public void testExecuteUpdate() throws Exception { + String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), + DEFAULT_DATABASE_NAME); + Connection conn = DriverManager.getConnection(connUri); + assertTrue(conn.isValid(100)); + + int result; + Statement stmt = null; + ResultSet res = null; + + try { + stmt = conn.createStatement(); + result = stmt.executeUpdate("create table table1 (id int, name text, score double, regdate timestamp)"); + assertEquals(result, 1); + + res = stmt.executeQuery("select * from table1"); + assertFalse(res.next()); + + ResultSetMetaData rsmd = res.getMetaData(); + assertNotNull(rsmd); + assertEquals(4, rsmd.getColumnCount()); + + assertEquals("id", rsmd.getColumnName(1)); + assertEquals("name", rsmd.getColumnName(2)); + assertEquals("score", rsmd.getColumnName(3)); + assertEquals("regdate", rsmd.getColumnName(4)); + + assertEquals("integer", rsmd.getColumnTypeName(1)); + assertEquals("varchar", rsmd.getColumnTypeName(2)); + assertEquals("float8", rsmd.getColumnTypeName(3)); + assertEquals("timestamp", rsmd.getColumnTypeName(4)); + } finally { + if(res != null) { + res.close(); + } + if(stmt != null) { + stmt.close(); + } + } + } + } \ No newline at end of file diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java index 5dae67e0e9..ece4fc82c2 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java @@ -1,4 +1,4 @@ -package org.apache.tajo.jdbc; /** +/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,6 +16,8 @@ * limitations under the License. */ +package org.apache.tajo.jdbc; + import org.apache.tajo.datum.Datum; import org.apache.tajo.datum.NullDatum; import org.apache.tajo.datum.ProtobufDatum; From 1f68c92b91031eee907bb375c79695a4b6813859 Mon Sep 17 00:00:00 2001 From: JaeHwa Jung Date: Mon, 17 Nov 2014 20:48:35 +0900 Subject: [PATCH 2/3] Added missing files. --- .../org/apache/tajo/client/ResultSetUtil.java | 4 + .../org/apache/tajo/jdbc/TestTajoJdbc.java | 156 ++++++++++++------ .../dataset/TestTajoJdbc/table1/table1.tbl | 5 + .../create_table_with_date_ddl.sql | 10 ++ .../TestTajoJdbc/testSortWithDateTime.result | 7 + 5 files changed, 129 insertions(+), 53 deletions(-) create mode 100644 tajo-core/src/test/resources/dataset/TestTajoJdbc/table1/table1.tbl create mode 100644 tajo-core/src/test/resources/queries/TestTajoJdbc/create_table_with_date_ddl.sql create mode 100644 tajo-core/src/test/resources/results/TestTajoJdbc/testSortWithDateTime.result diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java index ad600a52a3..9211a1b851 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java @@ -77,6 +77,8 @@ public static String toSqlType(TajoDataTypes.DataType type) { return "date"; case TIMESTAMP: return "timestamp"; + case TIME: + return "time"; case VARCHAR: return "varchar"; case TEXT: @@ -108,6 +110,8 @@ public static int tajoTypeToSqlType(TajoDataTypes.DataType type) throws SQLExcep return Types.DATE; case TIMESTAMP: return Types.TIMESTAMP; + case TIME: + return Types.TIME; case VARCHAR: return Types.VARCHAR; case TEXT: diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java index c34dc2f4c9..ca84cdeafa 100644 --- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java +++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java @@ -26,6 +26,7 @@ import org.apache.tajo.catalog.Column; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.client.QueryClient; +import org.apache.tajo.conf.TajoConf; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -33,10 +34,7 @@ import java.net.InetSocketAddress; import java.sql.*; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME; import static org.junit.Assert.*; @@ -69,13 +67,13 @@ public void testAcceptURL() throws SQLException { @Test(expected = SQLException.class) public void testGetConnection() throws SQLException { DriverManager.getConnection("jdbc:taju://" + tajoMasterAddress.getHostName() + ":" + tajoMasterAddress.getPort() - + "/default"); + + "/default"); } @Test public void testStatement() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); + DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); assertTrue(conn.isValid(100)); @@ -85,10 +83,10 @@ public void testStatement() throws Exception { stmt = conn.createStatement(); res = stmt.executeQuery("select l_returnflag, l_linestatus, count(*) as count_order from lineitem " + - "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); + "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); try { - Map result = Maps.newHashMap(); + Map result = Maps.newHashMap(); result.put("NO", 3); result.put("RF", 2); @@ -108,10 +106,10 @@ public void testStatement() throws Exception { res.close(); } } finally { - if(res != null) { + if (res != null) { res.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } @@ -120,7 +118,7 @@ public void testStatement() throws Exception { @Test public void testPreparedStatement() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - TajoConstants.DEFAULT_DATABASE_NAME); + TajoConstants.DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); assertTrue(conn.isValid(100)); @@ -137,7 +135,7 @@ public void testPreparedStatement() throws Exception { */ String sql = - "select l_orderkey, l_quantity, l_returnflag from lineitem where l_quantity > ? and l_returnflag = ?"; + "select l_orderkey, l_quantity, l_returnflag from lineitem where l_quantity > ? and l_returnflag = ?"; stmt = conn.prepareStatement(sql); @@ -155,9 +153,9 @@ public void testPreparedStatement() throws Exception { try { int numRows = 0; String[] resultData = {"136.0N", "238.0N"}; - while(res.next()) { + while (res.next()) { assertEquals(resultData[numRows], - ("" + res.getObject(1).toString() + res.getObject(2).toString() + res.getObject(3).toString())); + ("" + res.getObject(1).toString() + res.getObject(2).toString() + res.getObject(3).toString())); numRows++; } assertEquals(2, numRows); @@ -179,9 +177,9 @@ public void testPreparedStatement() throws Exception { try { int numRows = 0; String[] resultData = {"345.0R", "349.0R"}; - while(res.next()) { + while (res.next()) { assertEquals(resultData[numRows], - ("" + res.getObject(1).toString() + res.getObject(2).toString() + res.getObject(3).toString())); + ("" + res.getObject(1).toString() + res.getObject(2).toString() + res.getObject(3).toString())); numRows++; } assertEquals(2, numRows); @@ -189,10 +187,10 @@ public void testPreparedStatement() throws Exception { res.close(); } } finally { - if(res != null) { + if (res != null) { res.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } @@ -201,7 +199,7 @@ public void testPreparedStatement() throws Exception { @Test public void testDatabaseMetaDataGetTable() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - TajoConstants.DEFAULT_DATABASE_NAME); + TajoConstants.DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); assertTrue(conn.isValid(100)); @@ -219,12 +217,12 @@ public void testDatabaseMetaDataGetTable() throws Exception { Set retrivedViaJavaAPI = new HashSet(client.getTableList("default")); Set retrievedViaJDBC = new HashSet(); - while(rs.next()) { + while (rs.next()) { retrievedViaJDBC.add(rs.getString("TABLE_NAME")); } assertEquals(retrievedViaJDBC, retrivedViaJavaAPI); } finally { - if(rs != null) { + if (rs != null) { rs.close(); } } @@ -236,7 +234,7 @@ public void testDatabaseMetaDataGetTable() throws Exception { @Test public void testDatabaseMetaDataGetColumns() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - TajoConstants.DEFAULT_DATABASE_NAME); + TajoConstants.DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); assertTrue(conn.isValid(100)); @@ -258,7 +256,7 @@ public void testDatabaseMetaDataGetColumns() throws Exception { List columns = tableDesc.getSchema().getColumns(); - while(rs.next()) { + while (rs.next()) { assertEquals(tableName, rs.getString("TABLE_NAME")); assertEquals(columns.get(numColumns).getSimpleName(), rs.getString("COLUMN_NAME")); // TODO assert type @@ -267,7 +265,7 @@ public void testDatabaseMetaDataGetColumns() throws Exception { assertEquals(16, numColumns); } finally { - if(rs != null) { + if (rs != null) { rs.close(); } } @@ -280,24 +278,24 @@ public void testDatabaseMetaDataGetColumns() throws Exception { @Test public void testMultipleConnections() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - TajoConstants.DEFAULT_DATABASE_NAME); + TajoConstants.DEFAULT_DATABASE_NAME); Connection[] conns = new Connection[2]; conns[0] = DriverManager.getConnection(connUri); conns[1] = DriverManager.getConnection(connUri); try { - for(int i = 0; i < conns.length; i++) { + for (int i = 0; i < conns.length; i++) { Statement stmt = null; ResultSet res = null; try { stmt = conns[i].createStatement(); res = stmt.executeQuery("select l_returnflag, l_linestatus, count(*) as count_order from lineitem " + - "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); + "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); try { - Map result = Maps.newHashMap(); + Map result = Maps.newHashMap(); result.put("NO", 3); result.put("RF", 2); @@ -317,10 +315,10 @@ public void testMultipleConnections() throws Exception { res.close(); } } finally { - if(res != null) { + if (res != null) { res.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } @@ -338,24 +336,24 @@ public void testMultipleConnections() throws Exception { @Test public void testMultipleConnectionsSequentialClose() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); + DEFAULT_DATABASE_NAME); Connection[] conns = new Connection[2]; conns[0] = DriverManager.getConnection(connUri); conns[1] = DriverManager.getConnection(connUri); try { - for(int i = 0; i < conns.length; i++) { + for (int i = 0; i < conns.length; i++) { Statement stmt = null; ResultSet res = null; try { stmt = conns[i].createStatement(); res = stmt.executeQuery("select l_returnflag, l_linestatus, count(*) as count_order from lineitem " + - "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); + "group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus"); try { - Map result = Maps.newHashMap(); + Map result = Maps.newHashMap(); result.put("NO", 3); result.put("RF", 2); @@ -375,22 +373,22 @@ public void testMultipleConnectionsSequentialClose() throws Exception { res.close(); } } finally { - if(res != null) { + if (res != null) { res.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } conns[i].close(); } } } finally { - if(!conns[0].isClosed()) { + if (!conns[0].isClosed()) { assertTrue(conns[0].isValid(100)); conns[0].close(); assertFalse(conns[0].isValid(100)); } - if(!conns[1].isClosed()) { + if (!conns[1].isClosed()) { assertTrue(conns[1].isValid(100)); conns[1].close(); assertFalse(conns[1].isValid(100)); @@ -405,7 +403,7 @@ public void testSetStatement() throws Exception { assertFalse(TajoStatement.isSetVariableQuery("--SET JOIN_TASK_INPUT_SIZE 123")); String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); + DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); @@ -419,7 +417,7 @@ public void testSetStatement() throws Exception { assertNotNull(rsmd); assertEquals(0, rsmd.getColumnCount()); - QueryClient connTajoClient = ((JdbcConnection)stmt.getConnection()).getQueryClient(); + QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient(); Map variables = connTajoClient.getAllSessionVariables(); String value = variables.get("JOIN_TASK_INPUT_SIZE"); assertNotNull(value); @@ -447,7 +445,7 @@ public void testSetStatement() throws Exception { @Test public void testSetPreparedStatement() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); + DEFAULT_DATABASE_NAME); Connection conn = DriverManager.getConnection(connUri); @@ -461,7 +459,7 @@ public void testSetPreparedStatement() throws Exception { assertNotNull(rsmd); assertEquals(0, rsmd.getColumnCount()); - QueryClient connTajoClient = ((JdbcConnection)stmt.getConnection()).getQueryClient(); + QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient(); Map variables = connTajoClient.getAllSessionVariables(); String value = variables.get("JOIN_TASK_INPUT_SIZE"); assertNotNull(value); @@ -489,19 +487,20 @@ public void testSetPreparedStatement() throws Exception { } @Test - public void testExecuteUpdate() throws Exception { - String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); - Connection conn = DriverManager.getConnection(connUri); - assertTrue(conn.isValid(100)); - + public void testCreateTableWithDateAndTimestamp() throws Exception { int result; Statement stmt = null; ResultSet res = null; try { + String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), + DEFAULT_DATABASE_NAME); + Connection conn = DriverManager.getConnection(connUri); + assertTrue(conn.isValid(100)); + stmt = conn.createStatement(); - result = stmt.executeUpdate("create table table1 (id int, name text, score double, regdate timestamp)"); + result = stmt.executeUpdate("create table table1 (id int, name text, score double" + + ", register_date timestamp, update_date date, send_date time)"); assertEquals(result, 1); res = stmt.executeQuery("select * from table1"); @@ -509,25 +508,76 @@ public void testExecuteUpdate() throws Exception { ResultSetMetaData rsmd = res.getMetaData(); assertNotNull(rsmd); - assertEquals(4, rsmd.getColumnCount()); + assertEquals(6, rsmd.getColumnCount()); assertEquals("id", rsmd.getColumnName(1)); assertEquals("name", rsmd.getColumnName(2)); assertEquals("score", rsmd.getColumnName(3)); - assertEquals("regdate", rsmd.getColumnName(4)); + assertEquals("register_date", rsmd.getColumnName(4)); + assertEquals("update_date", rsmd.getColumnName(5)); + assertEquals("send_date", rsmd.getColumnName(6)); assertEquals("integer", rsmd.getColumnTypeName(1)); assertEquals("varchar", rsmd.getColumnTypeName(2)); assertEquals("float8", rsmd.getColumnTypeName(3)); assertEquals("timestamp", rsmd.getColumnTypeName(4)); + assertEquals("date", rsmd.getColumnTypeName(5)); + assertEquals("time", rsmd.getColumnTypeName(6)); + } finally { - if(res != null) { + if (res != null) { res.close(); } - if(stmt != null) { + if (stmt != null) { stmt.close(); } } } + @Test + public void testSortWithDateTime() throws Exception { + Statement stmt = null; + ResultSet res = null; + + // skip this test if catalog uses HCatalogStore. + // It is because HCatalogStore does not support Time data type. + TimeZone oldTimeZone = TajoConf.setCurrentTimeZone(TimeZone.getTimeZone("UTC")); + TimeZone systemOldTimeZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + + try { + if (!testingCluster.isHCatalogStoreRunning()) { + executeDDL("create_table_with_date_ddl.sql", "table1"); + + String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), + tajoMasterAddress.getPort(), "TestTajoJdbc"); + + Connection conn = DriverManager.getConnection(connUri); + assertTrue(conn.isValid(100)); + + stmt = conn.createStatement(); + res = stmt.executeQuery("select col1, col2, col3 from table1 order by col1, col2, col3"); + + ResultSetMetaData rsmd = res.getMetaData(); + assertNotNull(rsmd); + assertEquals(3, rsmd.getColumnCount()); + + assertEquals("timestamp", rsmd.getColumnTypeName(1)); + assertEquals("date", rsmd.getColumnTypeName(2)); + assertEquals("time", rsmd.getColumnTypeName(3)); + + assertResultSet(res); + } + } finally { + TajoConf.setCurrentTimeZone(oldTimeZone); + TimeZone.setDefault(systemOldTimeZone); + + if (res != null) { + res.close(); + } + if (stmt != null) { + stmt.close(); + } + } + } } \ No newline at end of file diff --git a/tajo-core/src/test/resources/dataset/TestTajoJdbc/table1/table1.tbl b/tajo-core/src/test/resources/dataset/TestTajoJdbc/table1/table1.tbl new file mode 100644 index 0000000000..52fa2fed9e --- /dev/null +++ b/tajo-core/src/test/resources/dataset/TestTajoJdbc/table1/table1.tbl @@ -0,0 +1,5 @@ +1997-11-09 20:34:56|1996-04-12|15:34:56 +1997-11-09 20:34:56|1996-03-13|19:34:56 +1993-11-09 20:34:56|1997-01-28|08:34:56 +1995-11-09 20:34:56|1994-02-02|17:34:56 +1995-11-09 20:34:56|1993-11-09|20:34:56 diff --git a/tajo-core/src/test/resources/queries/TestTajoJdbc/create_table_with_date_ddl.sql b/tajo-core/src/test/resources/queries/TestTajoJdbc/create_table_with_date_ddl.sql new file mode 100644 index 0000000000..846cbb63be --- /dev/null +++ b/tajo-core/src/test/resources/queries/TestTajoJdbc/create_table_with_date_ddl.sql @@ -0,0 +1,10 @@ +-- Sort Table +-- It is used in TestSortQuery::testSortWithDate + +create external table table1 ( + col1 timestamp, + col2 date, + col3 time +) using csv +with ('csvfile.delimiter'='|', 'csvfile.null'='NULL') +location ${table.path}; \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestTajoJdbc/testSortWithDateTime.result b/tajo-core/src/test/resources/results/TestTajoJdbc/testSortWithDateTime.result new file mode 100644 index 0000000000..118909c959 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoJdbc/testSortWithDateTime.result @@ -0,0 +1,7 @@ +col1,col2,col3 +------------------------------- +1993-11-09 20:34:56,1997-01-28,08:34:56 +1995-11-09 20:34:56,1993-11-09,20:34:56 +1995-11-09 20:34:56,1994-02-02,17:34:56 +1997-11-09 20:34:56,1996-03-13,19:34:56 +1997-11-09 20:34:56,1996-04-12,15:34:56 \ No newline at end of file From c0a134a929f18c5b626f96f6133348a59fa0b133 Mon Sep 17 00:00:00 2001 From: JaeHwa Jung Date: Tue, 18 Nov 2014 12:43:59 +0900 Subject: [PATCH 3/3] Fixed a unit test error --- .../org/apache/tajo/jdbc/TestTajoJdbc.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java index ca84cdeafa..a004baa829 100644 --- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java +++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java @@ -38,6 +38,7 @@ import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME; import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; @Category(IntegrationTest.class) public class TestTajoJdbc extends QueryTestCaseBase { @@ -488,6 +489,8 @@ public void testSetPreparedStatement() throws Exception { @Test public void testCreateTableWithDateAndTimestamp() throws Exception { + String tableName = CatalogUtil.normalizeIdentifier("testCreateTableWithDateAndTimestamp"); + int result; Statement stmt = null; ResultSet res = null; @@ -499,11 +502,11 @@ public void testCreateTableWithDateAndTimestamp() throws Exception { assertTrue(conn.isValid(100)); stmt = conn.createStatement(); - result = stmt.executeUpdate("create table table1 (id int, name text, score double" + result = stmt.executeUpdate("create table " + tableName + " (id int, name text, score double" + ", register_date timestamp, update_date date, send_date time)"); assertEquals(result, 1); - res = stmt.executeQuery("select * from table1"); + res = stmt.executeQuery("select * from " + tableName); assertFalse(res.next()); ResultSetMetaData rsmd = res.getMetaData(); @@ -525,9 +528,7 @@ public void testCreateTableWithDateAndTimestamp() throws Exception { assertEquals("time", rsmd.getColumnTypeName(6)); } finally { - if (res != null) { - res.close(); - } + cleanupQuery(res); if (stmt != null) { stmt.close(); } @@ -538,13 +539,14 @@ public void testCreateTableWithDateAndTimestamp() throws Exception { public void testSortWithDateTime() throws Exception { Statement stmt = null; ResultSet res = null; + int result; // skip this test if catalog uses HCatalogStore. // It is because HCatalogStore does not support Time data type. TimeZone oldTimeZone = TajoConf.setCurrentTimeZone(TimeZone.getTimeZone("UTC")); TimeZone systemOldTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - + try { if (!testingCluster.isHCatalogStoreRunning()) { executeDDL("create_table_with_date_ddl.sql", "table1"); @@ -567,14 +569,16 @@ public void testSortWithDateTime() throws Exception { assertEquals("time", rsmd.getColumnTypeName(3)); assertResultSet(res); + + result = stmt.executeUpdate("drop table table1"); + assertEquals(result, 1); + } } finally { TajoConf.setCurrentTimeZone(oldTimeZone); TimeZone.setDefault(systemOldTimeZone); - if (res != null) { - res.close(); - } + cleanupQuery(res); if (stmt != null) { stmt.close(); }