[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-21 Thread JIRA

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14901110#comment-14901110
 ] 

Sergio Peña commented on HIVE-11748:


Got it.
Thanks [~awsmithson] for the explanation.

Then there's no issue right now, but we're fixing the API to avoid an issue in 
the future.
The change looks good. +1

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
>Assignee: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is because the following HQL is generated/executed by calling 
> toString() on the Timestamp value:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = 2013-01-01 00:00:00.0
> {noformat}
> We should be quoting the value of Timestamp.toString(), so that the following 
> HQL is generated/executed:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = '2013-01-01 00:00:00.0'
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-21 Thread JIRA

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14901273#comment-14901273
 ] 

Sergio Peña commented on HIVE-11748:


Got it. Thanks for explaining.
Still +1. 

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
>Assignee: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is because the following HQL is generated/executed by calling 
> toString() on the Timestamp value:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = 2013-01-01 00:00:00.0
> {noformat}
> We should be quoting the value of Timestamp.toString(), so that the following 
> HQL is generated/executed:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = '2013-01-01 00:00:00.0'
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-21 Thread Angus Smithson (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14901184#comment-14901184
 ] 

Angus Smithson commented on HIVE-11748:
---

[~spena] - just to be clear, there are two changes to 
HivePreparedStatement.java, from the diff:
{noformat}
diff --git jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java 
jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
index 7687537..c28b7d6 100644
--- jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
+++ jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
@@ -607,7 +607,7 @@ public void setObject(int parameterIndex, Object x) throws 
SQLException {
 } else if (x instanceof Character) {
   setString(parameterIndex, x.toString());
 } else if (x instanceof Timestamp) {
-  setString(parameterIndex, x.toString());
+  setTimestamp(parameterIndex, (Timestamp) x);
 } else if (x instanceof BigDecimal) {
   setString(parameterIndex, x.toString());
 } else {
@@ -728,7 +728,7 @@ public void setTime(int parameterIndex, Time x, Calendar 
cal) throws SQLExceptio
*/
 
   public void setTimestamp(int parameterIndex, Timestamp x) throws 
SQLException {
-this.parameters.put(parameterIndex, x.toString());
+this.parameters.put(parameterIndex, "'" + x.toString() + "'");
   }
 
   /*
{noformat}

The first change makes {{setObject(int parameterIndex, Object x)}} call 
{{setTimestamp(int parameterIndex, Timestamp x)}} when passed a Timestamp.  
That change is simply to maintain consistency in future.

The second change is modifying {{setTimestamp(int parameterIndex, Timestamp 
x)}} to quote the value it is passed.  Prior to this change it was broken (see 
the issue description).

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
>Assignee: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> 

[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-18 Thread Angus Smithson (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14852716#comment-14852716
 ] 

Angus Smithson commented on HIVE-11748:
---

Thanks for taknig a look [~spena].


I assume you're refering to this part of the diff, in {{setObject(int 
parameterIndex, Object x)}}?
{noformat}
 } else if (x instanceof Timestamp) {
-  setString(parameterIndex, x.toString());
+  setTimestamp(parameterIndex, (Timestamp) x);
 } else if (x instanceof BigDecimal) {
{noformat}

\\

I updated it to call setTimestamp so that if anyone modifies 
{{setTimestamp(...)}} in future, we get the same behaviour...
{code}
HivePreparedStatement hps = ;
Timestamp timestamp = ;

// The following two method calls should result in exactly the same behavior.
// The caller should be able to call either, depending on the situation.
hps.setObject(1, timestamp);
hps.setTimestamp(1, timestamp);
{code}

Prior to this (HIVE-11748) fix, those two calls resulted in different behavior, 
which I think constitutes a bug.  If we leave {{setObject()}} calling 
{{setString(...)}} and someone modifies {{setTimestamp(...)}} in future, we are 
back in a place where each provides different behavior (IMO, a bug).

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
>Assignee: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> 

[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-17 Thread JIRA

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14804451#comment-14804451
 ] 

Sergio Peña commented on HIVE-11748:


Thanks [~awsmithson] for the patch.
Just one question:

I see this line was replaced {{setString(parameterIndex, x.toString());}} by 
{{setTimestamp(parameterIndex, (Timestamp) x);}} And internally, {{setString}} 
wraps the string with single-qutoes:
{code}
public void setString(int parameterIndex, String x) throws SQLException {
 x=x.replace("'", "\\'");
 this.parameters.put(parameterIndex,"'"+x+"'");
  }

public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
this.parameters.put(parameterIndex, "'" + x.toString() + "'");
  }
{code}

What is the difference between setString and setTimestamp? I run the test 
{{testPrepareSetTimestamp}} with and without the above line replaced, and it 
seems to work.

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is because the following HQL is generated/executed by calling 
> toString() on the Timestamp value:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = 2013-01-01 00:00:00.0
> {noformat}
> We should be quoting the value of Timestamp.toString(), so that the following 
> HQL is generated/executed:
> {noformat}
> 

[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-15 Thread Angus Smithson (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14745321#comment-14745321
 ] 

Angus Smithson commented on HIVE-11748:
---

[~szehon] / [~spena] - are you willing/able to review this change?

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is because the following HQL is generated/executed by calling 
> toString() on the Timestamp value:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = 2013-01-01 00:00:00.0
> {noformat}
> We should be quoting the value of Timestamp.toString(), so that the following 
> HQL is generated/executed:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = '2013-01-01 00:00:00.0'
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-07 Thread Hive QA (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14733889#comment-14733889
 ] 

Hive QA commented on HIVE-11748:




{color:red}Overall{color}: -1 at least one tests failed

Here are the results of testing the latest attachment:
https://issues.apache.org/jira/secure/attachment/12754494/HIVE-11748.2.patch

{color:red}ERROR:{color} -1 due to 1 failed/errored test(s), 9421 tests executed
*Failed tests:*
{noformat}
org.apache.hive.hcatalog.api.TestHCatClient.testTableSchemaPropagation
{noformat}

Test results: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/jenkins/job/PreCommit-HIVE-TRUNK-Build/5191/testReport
Console output: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/jenkins/job/PreCommit-HIVE-TRUNK-Build/5191/console
Test logs: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/logs/PreCommit-HIVE-TRUNK-Build-5191/

Messages:
{noformat}
Executing org.apache.hive.ptest.execution.PrepPhase
Executing org.apache.hive.ptest.execution.ExecutionPhase
Executing org.apache.hive.ptest.execution.ReportingPhase
Tests exited with: TestsFailedException: 1 tests failed
{noformat}

This message is automatically generated.

ATTACHMENT ID: 12754494 - PreCommit-HIVE-TRUNK-Build

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is 

[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-07 Thread Angus Smithson (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14733905#comment-14733905
 ] 

Angus Smithson commented on HIVE-11748:
---

The {{org.apache.hive.hcatalog.api.TestHCatClient.testTableSchemaPropagation}} 
test failure is unrelated, it was failing prior to my changes.

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
> Attachments: HIVE-11748.2.patch, HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
> org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
>   at 
> org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
>   at 
> org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp(TestJdbcDriver2.java:2395)
> {noformat}
> The failure is because the following HQL is generated/executed by calling 
> toString() on the Timestamp value:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = 2013-01-01 00:00:00.0
> {noformat}
> We should be quoting the value of Timestamp.toString(), so that the following 
> HQL is generated/executed:
> {noformat}
> SELECT * FROM testdatatypetable WHERE c20 = '2013-01-01 00:00:00.0'
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (HIVE-11748) HivePreparedStatement's setTimestamp() does not quote value as required

2015-09-06 Thread Hive QA (JIRA)

[ 
https://issues.apache.org/jira/browse/HIVE-11748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14732481#comment-14732481
 ] 

Hive QA commented on HIVE-11748:




{color:red}Overall{color}: -1 at least one tests failed

Here are the results of testing the latest attachment:
https://issues.apache.org/jira/secure/attachment/12754399/HIVE-11748.patch

{color:red}ERROR:{color} -1 due to 5 failed/errored test(s), 9421 tests executed
*Failed tests:*
{noformat}
org.apache.hadoop.hive.cli.TestMinimrCliDriver.testCliDriver_stats_counter
org.apache.hive.hcatalog.api.TestHCatClient.testTableSchemaPropagation
org.apache.hive.hcatalog.streaming.TestStreaming.testEndpointConnection
org.apache.hive.hcatalog.streaming.TestStreaming.testTimeOutReaper
org.apache.hive.jdbc.TestJdbcDriver2.testPrepareSetTimestamp
{noformat}

Test results: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/jenkins/job/PreCommit-HIVE-TRUNK-Build/5190/testReport
Console output: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/jenkins/job/PreCommit-HIVE-TRUNK-Build/5190/console
Test logs: 
http://ec2-174-129-184-35.compute-1.amazonaws.com/logs/PreCommit-HIVE-TRUNK-Build-5190/

Messages:
{noformat}
Executing org.apache.hive.ptest.execution.PrepPhase
Executing org.apache.hive.ptest.execution.ExecutionPhase
Executing org.apache.hive.ptest.execution.ReportingPhase
Tests exited with: TestsFailedException: 5 tests failed
{noformat}

This message is automatically generated.

ATTACHMENT ID: 12754399 - PreCommit-HIVE-TRUNK-Build

> HivePreparedStatement's setTimestamp() does not quote value as required
> ---
>
> Key: HIVE-11748
> URL: https://issues.apache.org/jira/browse/HIVE-11748
> Project: Hive
>  Issue Type: Bug
>  Components: JDBC
>Reporter: Angus Smithson
> Attachments: HIVE-11748.patch
>
>
> [HivePreparedStatement.setTimestamp(int parameterIndex, Timestamp 
> x)|https://hive.apache.org/javadocs/r1.2.1/api/org/apache/hive/jdbc/HivePreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)]
>  does not quote the Timestamp value when generating the HQL statement, 
> resulting in a HiveSqlException on execution.
> h5. Reproducing
> If we add the following unit test to 
> {{itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java}}:
> {code}
>   @Test
>   public void testPrepareSetTimestamp() throws SQLException, ParseException {
> String sql = String.format("SELECT * FROM %s WHERE c20 = ?", 
> dataTypeTableName);
> try (PreparedStatement ps = con.prepareStatement(sql)) {
>   Timestamp timestamp = new Timestamp(new 
> SimpleDateFormat("-MM-dd").parse("2013-01-01").getTime());
>   ps.setTimestamp(1, timestamp);
>   try (ResultSet resultSet = ps.executeQuery()) {
> assertTrue(resultSet.next());
> assertEquals("2013-01-01", resultSet.getString(20));
>   }
> }
>   }
> {code}
> The test fails:
> {noformat}
> org.apache.hive.service.cli.HiveSQLException: Error while compiling 
> statement: FAILED: ParseException line 1:55 cannot recognize input near '00' 
> ':' '00' in expression specification
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:205)
>   at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:401)
>   at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:310)
>   at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1150)
>   at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1136)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:109)
>   at 
> org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:180)
>   at 
> org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:405)
>   at 
> org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:392)
>   at 
> org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:261)
>   at 
> org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)
>   at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:606)
>   at 
> org.apache.hive.jdbc.HiveConnection$SynchronizedHandler.invoke(HiveConnection.java:1400)
>   at com.sun.proxy.$Proxy32.ExecuteStatement(Unknown Source)
>   at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:246)
>   at 
>