calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject calcite git commit: [CALCITE-1287] TCK test for binary columns
Date Fri, 10 Jun 2016 21:40:58 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 717f59177 -> 113a034ec


[CALCITE-1287] TCK test for binary columns


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/113a034e
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/113a034e
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/113a034e

Branch: refs/heads/master
Commit: 113a034ec1689dd8313af5d2f2d2431f1e666eaa
Parents: 717f591
Author: Josh Elser <elserj@apache.org>
Authored: Fri Jun 10 17:11:30 2016 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Fri Jun 10 17:40:39 2016 -0400

----------------------------------------------------------------------
 .../calcite/avatica/tck/tests/BinaryTest.java   | 105 +++++++++++++++++++
 1 file changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/113a034e/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BinaryTest.java
----------------------------------------------------------------------
diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BinaryTest.java
b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BinaryTest.java
new file mode 100644
index 0000000..50c7082
--- /dev/null
+++ b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BinaryTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.calcite.avatica.tck.tests;
+
+import org.junit.Test;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * TCK test case to verify binary data can be written and read correctly.
+ */
+public class BinaryTest extends BaseTckTest {
+
+  @Test public void readWriteBinaryData() throws Exception {
+    final String tableName = getTableName();
+    try (Statement stmt = connection.createStatement()) {
+      assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName));
+      String sql = "CREATE TABLE " + tableName
+          + " (pk integer not null primary key, col1 binary(10))";
+      assertFalse(stmt.execute(sql));
+
+      try (PreparedStatement pstmt = connection.prepareStatement("INSERT INTO " + tableName
+          + " values (?,?)")) {
+        for (int i = 0; i < 10; i++) {
+          pstmt.setInt(1, i);
+          pstmt.setBytes(2, ("bytes" + i).getBytes(UTF_8));
+          assertEquals(1, pstmt.executeUpdate());
+        }
+      }
+
+      ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName);
+      assertNotNull(results);
+      for (int i = 0; i < 10; i++) {
+        assertTrue(results.next());
+        assertEquals(i, results.getInt(1));
+        byte[] expectedContent = ("bytes" + i).getBytes(UTF_8);
+        byte[] expected = new byte[10];
+        System.arraycopy(expectedContent, 0, expected, 0, expectedContent.length);
+        assertArrayEquals(expected, results.getBytes(2));
+      }
+      assertFalse(results.next());
+      results.close();
+    }
+  }
+
+  @Test public void selectivelyReadBinaryData() throws Exception {
+    final String tableName = getTableName();
+    try (Statement stmt = connection.createStatement()) {
+      assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName));
+      String sql = "CREATE TABLE " + tableName
+          + " (pk integer not null primary key, col1 binary(10))";
+      assertFalse(stmt.execute(sql));
+
+      try (PreparedStatement pstmt = connection.prepareStatement("INSERT INTO " + tableName
+          + " values (?,?)")) {
+        for (int i = 0; i < 10; i++) {
+          pstmt.setInt(1, i);
+          pstmt.setBytes(2, ("bytes" + i).getBytes(UTF_8));
+          assertEquals(1, pstmt.executeUpdate());
+        }
+      }
+
+      try (PreparedStatement pstmt = connection.prepareStatement("SELECT * FROM " + tableName
+          + " WHERE col1 = ?")) {
+        byte[] expectedContent = ("bytes" + 4).getBytes(UTF_8);
+        byte[] expected = new byte[10];
+        System.arraycopy(expectedContent, 0, expected, 0, expectedContent.length);
+        pstmt.setBytes(1, expected);
+        ResultSet results = pstmt.executeQuery();
+        assertNotNull(results);
+        assertTrue(results.next());
+        assertEquals(4, results.getInt(1));
+        assertArrayEquals(expected, results.getBytes(2));
+        assertFalse(results.next());
+        results.close();
+      }
+    }
+  }
+}
+
+// End BinaryTest.java


Mime
View raw message