You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pa...@apache.org on 2015/03/27 18:49:20 UTC
[2/6] drill git commit: DRILL-2439: Fix: getBoolean() doesn't work
(for non-null values).
DRILL-2439: Fix: getBoolean() doesn't work (for non-null values).
- Created regression test Drill2439GetBooleanSaysWrongTypeBugTest.
- Added getBoolean(...) for SqlAccessor implementations for type Bit in
SqlAccessors template.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/9a5b50ea
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/9a5b50ea
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/9a5b50ea
Branch: refs/heads/master
Commit: 9a5b50ea52ee60a355926ac0d52ab87fafb592c0
Parents: 83ebf4f
Author: dbarclay <db...@maprtech.com>
Authored: Fri Mar 20 22:14:56 2015 -0700
Committer: Parth Chandra <pc...@maprtech.com>
Committed: Fri Mar 27 10:19:23 2015 -0700
----------------------------------------------------------------------
.../main/codegen/templates/SqlAccessors.java | 13 ++++
...39GetBooleanFailsSayingWrongTypeBugTest.java | 80 ++++++++++++++++++++
2 files changed, 93 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/9a5b50ea/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
index a838e11..c0ece9b 100644
--- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
+++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
@@ -270,6 +270,19 @@ public class ${name}Accessor extends AbstractSqlAccessor {
}
</#if>
+
+ <#if minor.class == "Bit" >
+ public boolean getBoolean(int index) {
+ <#if mode == "Nullable">
+ if (ac.isNull(index)) {
+ return false;
+ }
+ </#if>
+ return 1 == ac.get(index);
+ }
+ </#if>
+
+
</#if> <#-- not VarLen -->
}
http://git-wip-us.apache.org/repos/asf/drill/blob/9a5b50ea/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java
new file mode 100644
index 0000000..69f194a
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.drill.jdbc.test;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.*;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.drill.jdbc.Driver;
+import org.apache.drill.jdbc.JdbcTest;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+public class Drill2439GetBooleanFailsSayingWrongTypeBugTest extends JdbcTest {
+
+ private static Connection connection;
+ private static Statement statement;
+
+ @BeforeClass
+ public static void setUpConnection() throws SQLException {
+ connection = new Driver().connect( "jdbc:drill:zk=local", null );
+ statement = connection.createStatement();
+ }
+
+ @AfterClass
+ public static void tearDownConnection() throws SQLException {
+ connection.close();
+ }
+
+ @Test
+ public void testGetBooleanGetsTrue() throws Exception {
+ ResultSet rs =
+ statement.executeQuery( "SELECT TRUE FROM INFORMATION_SCHEMA.CATALOGS" );
+ rs.next();
+ assertThat( "getBoolean(...) for TRUE", rs.getBoolean( 1 ), equalTo( true ) );
+ assertThat( "wasNull", rs.wasNull(), equalTo( false ) );
+ }
+
+ @Test
+ public void testGetBooleanGetsFalse() throws Exception {
+ ResultSet rs =
+ statement.executeQuery( "SELECT FALSE FROM INFORMATION_SCHEMA.CATALOGS" );
+ rs.next();
+ assertThat( "getBoolean(...) for FALSE", rs.getBoolean( 1 ), equalTo( false ) );
+ assertThat( "wasNull", rs.wasNull(), equalTo( false ) );
+ }
+
+ @Test
+ public void testGetBooleanGetsNull() throws Exception {
+ ResultSet rs = statement.executeQuery(
+ "SELECT CAST( NULL AS BOOLEAN ) FROM INFORMATION_SCHEMA.CATALOGS" );
+ rs.next();
+ assertThat( "getBoolean(...) for BOOLEAN NULL", rs.getBoolean( 1 ), equalTo( false ) );
+ assertThat( "wasNull", rs.wasNull(), equalTo( true ) );
+ }
+
+}