richardantal commented on code in PR #1571:
URL: https://github.com/apache/phoenix/pull/1571#discussion_r1143628015


##########
phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java:
##########
@@ -85,6 +86,19 @@ public Boolean toObject(byte[] bytes, int offset, int 
length, PDataType actualTy
         return null;
     }
 
+    @Override
+    public Object toObject(byte[] bytes, int offset, int length, PDataType 
actualType,
+            SortOrder sortOrder, Integer maxLength, Integer scale, Class 
jdbcType)
+            throws SQLException {
+        // FIXME according to the JDBC spec, we should support all these types:

Review Comment:
   Could you please create a follow up ticket for this?



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/GetSetObjectIT.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.expression.function.SqrtFunction;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * End to end tests for {@link SqrtFunction}
+ */
+@Category(ParallelStatsDisabledTest.class)
+public class GetSetObjectIT extends ParallelStatsDisabledIT {
+
+    // Temporals are tested in DateTimeIT
+    // Arrays are tested in Array1IT
+
+    @Test
+    public void testNonNumeric() throws SQLException {
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        String tableName = generateUniqueName();
+
+        byte[] bytes = { 1, 2 };
+        String characters = "11";
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);
+                Statement stmt = conn.createStatement();
+                PreparedStatement insertStmt =
+                        conn.prepareStatement("upsert into " + tableName
+                                + "(id, binary_col, varbinary_col, 
boolean_col, char_col, varchar_col) values (?,?,?,?,?,?)")) {
+            stmt.executeUpdate("CREATE TABLE " + tableName
+                    + " (ID INTEGER PRIMARY KEY, BINARY_COL BINARY(2), 
VARBINARY_COL VARBINARY, BOOLEAN_COL BOOLEAN, CHAR_COL CHAR(2), VARCHAR_COL 
VARCHAR)");
+            insertStmt.setInt(1, 1);
+            // The type specific setters also delegate to these
+            insertStmt.setObject(2, bytes);
+            insertStmt.setObject(3, bytes);
+            insertStmt.setObject(4, Boolean.TRUE);
+            insertStmt.setObject(5, characters);
+            insertStmt.setObject(6, characters);
+            insertStmt.executeUpdate();
+            conn.commit();
+
+            ResultSet rs = stmt.executeQuery("select * from " + tableName);
+            while (rs.next()) {
+                assertArrayEquals(bytes, rs.getBytes(2));
+                assertArrayEquals(bytes, (byte[]) rs.getObject(2));
+                assertArrayEquals(bytes, rs.getObject(2, byte[].class));
+                try {
+                    rs.getObject(2, Long.class);
+                    fail("We only implement byte[]");
+                } catch (SQLException e) {

Review Comment:
   We could assert on the errorCode or the error message containing Type 
mismatch when catching these expected Exceptions.



##########
phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java:
##########
@@ -528,16 +519,20 @@ public void setTimestamp(int parameterIndex, Timestamp x) 
throws SQLException {
 
     @Override
     public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) 
throws SQLException {
+        setParameter(parameterIndex, processTimestamp(x, cal));
+    }
+
+    private java.sql.Timestamp processTimestamp(Timestamp x, Calendar cal) {
         if (x != null) {
             if (connection.isApplyTimeZoneDisplacement()) {
-                x = DateUtil.applyInputDisplacement(x, cal.getTimeZone());
+                return DateUtil.applyInputDisplacement(x, cal.getTimeZone());
             } else {
                 int nanos = x.getNanos();
                 x = new Timestamp(x.getTime());
                 x.setNanos(nanos);

Review Comment:
   It feels a bit inconsistent to the other process functions, but I see the 
reason why



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to