http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/TestRunner.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/TestRunner.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/TestRunner.java deleted file mode 100644 index 6807354..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/TestRunner.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * 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; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.ClassPath; -import com.google.common.reflect.ClassPath.ClassInfo; - -import org.junit.runner.Description; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; -import org.junit.runner.notification.Failure; -import org.junit.runner.notification.RunListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Modifier; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -/** - * Entry point for running an Avatica cross-version compatibility test. - */ -public class TestRunner implements Runnable { - private static final Logger LOG = LoggerFactory.getLogger(TestRunner.class); - private static final String ANSI_RESET = "\u001B[0m"; - private static final String ANSI_RED = "\u001B[31m"; - private static final String ANSI_GREEN = "\u001B[32m"; - - private static Driver driver; - private static String driverUrl; - - @Parameter(names = { "-u", "--jdbcUrl" }, description = "JDBC URL for Avatica Driver") - private String jdbcUrl; - - private JUnitCore junitCore; - - /** - * Returns the {@link Connection} for tests to use. - * - * @return A JDBC Connection. - */ - public static Connection getConnection() throws SQLException { - if (null == driver) { - throw new IllegalStateException("JDBC Driver is not initialized"); - } - - return driver.connect(driverUrl, new Properties()); - } - - @Override public void run() { - // Construct the Connection - initializeDriver(); - - if (null == driver) { - LOG.error("Failed to find driver for {}", jdbcUrl); - Unsafe.systemExit(TestRunnerExitCodes.NO_SUCH_DRIVER.ordinal()); - return; - } - - // Initialize JUnit - initializeJUnit(); - - // Enumerate available test cases - final List<Class<?>> testClasses = getAllTestClasses(); - - final TestResults globalResults = new TestResults(); - - // Run each test case - for (Class<?> testClass : testClasses) { - runSingleTest(globalResults, testClass); - } - - System.out.println(globalResults.summarize()); - - if (globalResults.numFailed > 0) { - // Tests failed, don't exit normally - Unsafe.systemExit(TestRunnerExitCodes.FAILED_TESTS.ordinal()); - } else { - // Exited normally - Unsafe.systemExit(TestRunnerExitCodes.NORMAL.ordinal()); - } - } - - /** - * Finds all tests to run for the TCK. - * - * @return A list of test classes to run. - */ - List<Class<?>> getAllTestClasses() { - try { - ClassPath cp = ClassPath.from(getClass().getClassLoader()); - ImmutableSet<ClassInfo> classes = - cp.getTopLevelClasses("org.apache.calcite.avatica.tck.tests"); - - List<Class<?>> testClasses = new ArrayList<>(classes.size()); - for (ClassInfo classInfo : classes) { - if (classInfo.getSimpleName().equals("package-info")) { - continue; - } - Class<?> clz = Class.forName(classInfo.getName()); - if (Modifier.isAbstract(clz.getModifiers())) { - // Ignore abstract classes - continue; - } - testClasses.add(clz); - } - - return testClasses; - } catch (Exception e) { - LOG.error("Failed to instantiate test classes", e); - Unsafe.systemExit(TestRunnerExitCodes.TEST_CASE_INSTANTIATION.ordinal()); - // Unreachable.. - return null; - } - } - - void initializeDriver() { - try { - // Make sure the Avatica Driver gets loaded - Class.forName("org.apache.calcite.avatica.remote.Driver"); - driverUrl = jdbcUrl; - driver = DriverManager.getDriver(driverUrl); - } catch (SQLException e) { - LOG.error("Could not instantiate JDBC Driver with URL: '{}'", jdbcUrl, e); - Unsafe.systemExit(TestRunnerExitCodes.BAD_JDBC_URL.ordinal()); - } catch (ClassNotFoundException e) { - LOG.error("Could not load Avatica Driver class", e); - Unsafe.systemExit(TestRunnerExitCodes.MISSING_DRIVER_CLASS.ordinal()); - } - } - - /** - * Sets up JUnit to run the tests for us. - */ - void initializeJUnit() { - junitCore = new JUnitCore(); - - junitCore.addListener(new RunListener() { - @Override public void testStarted(Description description) throws Exception { - LOG.debug("Starting {}", description); - } - - @Override public void testFinished(Description description) throws Exception { - LOG.debug("{}Finished {}{}", ANSI_GREEN, description, ANSI_RESET); - } - - @Override public void testFailure(Failure failure) throws Exception { - LOG.info("{}Failed {}{}", ANSI_RED, failure.getDescription(), ANSI_RESET, - failure.getException()); - } - }); - } - - /** - * Runs a single test class, adding its results to <code>globalResults</code>. - * - * @param globalResults A global record of test results. - * @param testClass The test class to run. - */ - void runSingleTest(final TestResults globalResults, final Class<?> testClass) { - final String className = Objects.requireNonNull(testClass).getName(); - LOG.info("{}Running {}{}", ANSI_GREEN, className, ANSI_RESET); - - try { - Result result = junitCore.run(testClass); - globalResults.merge(testClass, result); - } catch (Exception e) { - // most likely JUnit issues, like no tests to run - LOG.error("{}Test failed: {}{}", ANSI_RED, className, ANSI_RESET, e); - } - } - - public static void main(String[] args) { - TestRunner runner = new TestRunner(); - - // Parse the args, sets it on runner. - new JCommander(runner, args); - - // Run the tests. - runner.run(); - } - - /** - * A container to track results from all tests executed. - */ - private static class TestResults { - private int numRun = 0; - private int numFailed = 0; - private int numIgnored = 0; - private List<Failure> failures = new ArrayList<>(); - - /** - * Updates the current state of <code>this</code> with the <code>result</code>. - * - * @param testClass The test class executed. - * @param result The results of the test class execution. - * @return <code>this</code> - */ - public TestResults merge(Class<?> testClass, Result result) { - LOG.info("Tests run: {}, Failures: {}, Skipped: {}, Time elapsed: {} - in {}", - result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(), - TimeUnit.SECONDS.convert(result.getRunTime(), TimeUnit.MILLISECONDS), - testClass.getName()); - - numRun += result.getRunCount(); - numFailed += result.getFailureCount(); - numIgnored += result.getIgnoreCount(); - - // Collect the failures - if (!result.wasSuccessful()) { - failures.addAll(result.getFailures()); - } - - return this; - } - - /** - * Constructs a human-readable summary of the success/failure of the tests executed. - * - * @return A summary in the form of a String. - */ - public String summarize() { - StringBuilder sb = new StringBuilder(64); - sb.append("\nTest Summary: Run: ").append(numRun).append(", Failed: ").append(numFailed); - sb.append(", Skipped: ").append(numIgnored); - if (numFailed > 0) { - sb.append(ANSI_RED).append("\n\nFailures:").append(ANSI_RESET).append("\n\n"); - for (Failure failure : failures) { - sb.append(failure.getTestHeader()).append(" ").append(failure.getMessage()).append("\n"); - } - } - return sb.toString(); - } - } - - /** - * ExitCodes set by {@link TestRunner}. - */ - private enum TestRunnerExitCodes { - // Position is important, ordinal() is used! - NORMAL, // 0, all tests passed - BAD_JDBC_URL, // 1 - TEST_CASE_INSTANTIATION, // 2 - NO_SUCH_DRIVER, // 3 - FAILED_TESTS, // 4 - MISSING_DRIVER_CLASS; // 5 - } -} - -// End TestRunner.java
http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/Unsafe.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/Unsafe.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/Unsafe.java deleted file mode 100644 index e88b6b7..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/Unsafe.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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; - -import java.util.Calendar; -import java.util.Locale; - -/** - * Contains methods that call JDK methods that the - * <a href="https://github.com/policeman-tools/forbidden-apis">forbidden - * APIs checker</a> does not approve of. - * - * <p>This class is excluded from the check, so methods called via this class - * will not fail the build. - */ -class Unsafe { - private Unsafe() {} - - /** Calls {@link System#exit}. */ - static void systemExit(int status) { - System.exit(status); - } - - /** Calls {@link Object#notifyAll()}. */ - public static void notifyAll(Object o) { - o.notifyAll(); - } - - /** Calls {@link Object#wait()}. */ - public static void wait(Object o) throws InterruptedException { - o.wait(); - } - - /** Returns a {@link Calendar} with the local time zone and root - * locale. */ - public static Calendar localCalendar() { - return Calendar.getInstance(Locale.ROOT); - } -} - -// End Unsafe.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/package-info.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/package-info.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/package-info.java deleted file mode 100644 index 77c2d16..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -/** - * Avatica compatibility framework. - */ -@PackageMarker -package org.apache.calcite.avatica.tck; - -// End package-info.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BaseTckTest.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BaseTckTest.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BaseTckTest.java deleted file mode 100644 index 8799cf1..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BaseTckTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.apache.calcite.avatica.tck.TestRunner; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; - -import java.sql.Connection; - -/** - * Base class for TCK tests. - */ -public abstract class BaseTckTest { - - @Rule public TestName name = new TestName(); - - protected Connection connection; - - @Before public void initializeConnection() throws Exception { - connection = TestRunner.getConnection(); - } - - @After public void closeConnection() throws Exception { - if (null != connection) { - connection.close(); - } - } - - protected Connection getConnection() { - return connection; - } - - protected String getTableName() { - return getClass().getSimpleName() + "_" + name.getMethodName(); - } -} - -// End BaseTckTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/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 deleted file mode 100644 index 50c7082..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/BinaryTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/InsertTest.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/InsertTest.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/InsertTest.java deleted file mode 100644 index 11c44d7..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/InsertTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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.Assume; -import org.junit.Test; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.Statement; -import java.util.Arrays; - -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; - -/** - * Tests for <code>INSERT</code>. - */ -public class InsertTest extends BaseTckTest { - - @Test public void simpleInsert() 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 varchar(10))"; - assertFalse(stmt.execute(sql)); - - for (int i = 0; i < 10; i++) { - sql = "INSERT INTO " + tableName + " values (" + i + ", '" + i + "')"; - assertEquals(1, stmt.executeUpdate(sql)); - } - - ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName); - assertNotNull(results); - for (int i = 0; i < 10; i++) { - assertTrue(results.next()); - assertEquals(i, results.getInt(1)); - assertEquals(Integer.toString(i), results.getString(1)); - } - assertFalse(results.next()); - results.close(); - } - } - - @Test public void preparedStatementInsert() throws Exception { - final String tableName = getTableName(); - final String insertSql = "INSERT INTO " + tableName + " values(?, ?)"; - 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 varchar(10))"; - assertFalse(stmt.execute(sql)); - - try (PreparedStatement pstmt = connection.prepareStatement(insertSql)) { - for (int i = 0; i < 10; i++) { - pstmt.setInt(1, i); - pstmt.setString(2, "a_" + Integer.toString(i)); - assertEquals(1, pstmt.executeUpdate()); - } - } - - ResultSet results = stmt.executeQuery("SELECT COUNT(pk) from " + tableName); - assertNotNull(results); - assertTrue(results.next()); - assertEquals(10, results.getInt(1)); - - results = stmt.executeQuery("SELECT * from " + tableName); - assertNotNull(results); - for (int i = 0; i < 10; i++) { - assertTrue(results.next()); - assertEquals(i, results.getInt(1)); - assertEquals("a_" + i, results.getString(2)); - } - assertFalse(results.next()); - results.close(); - } - } - - @Test public void batchInsert() 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 varchar(10))"; - assertFalse(stmt.execute(sql)); - - for (int i = 0; i < 10; i++) { - sql = "INSERT INTO " + tableName + " values (" + i + ", '" + i + "')"; - try { - stmt.addBatch(sql); - } catch (SQLFeatureNotSupportedException e) { - // batch isn't supported in this version, gracefully ignore, - Assume.assumeTrue("Batch update is not support by the client", false); - } - } - - int[] updateCounts = stmt.executeBatch(); - int[] expectedUpdateCounts = new int[10]; - Arrays.fill(expectedUpdateCounts, 1); - assertArrayEquals(expectedUpdateCounts, updateCounts); - - ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName); - assertNotNull(results); - for (int i = 0; i < 10; i++) { - assertTrue(results.next()); - assertEquals(i, results.getInt(1)); - assertEquals(Integer.toString(i), results.getString(1)); - } - assertFalse(results.next()); - results.close(); - } - } - - @Test public void preparedBatchInsert() throws Exception { - final String tableName = getTableName(); - final String insertSql = "INSERT INTO " + tableName + " values(?, ?)"; - 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 varchar(10))"; - assertFalse(stmt.execute(sql)); - - try (PreparedStatement pstmt = connection.prepareStatement(insertSql)) { - for (int i = 0; i < 10; i++) { - pstmt.setInt(1, i); - pstmt.setString(2, "a_" + Integer.toString(i)); - try { - pstmt.addBatch(); - } catch (SQLFeatureNotSupportedException e) { - // batch isn't supported in this version, gracefully ignore, - Assume.assumeTrue("Batch update is not support by the client", false); - } - } - - int[] updateCounts = pstmt.executeBatch(); - int[] expectedUpdateCounts = new int[10]; - Arrays.fill(expectedUpdateCounts, 1); - assertArrayEquals(expectedUpdateCounts, updateCounts); - } - - ResultSet results = stmt.executeQuery("SELECT COUNT(pk) from " + tableName); - assertNotNull(results); - assertTrue(results.next()); - assertEquals(10, results.getInt(1)); - - results = stmt.executeQuery("SELECT * from " + tableName); - assertNotNull(results); - for (int i = 0; i < 10; i++) { - assertTrue(results.next()); - assertEquals(i, results.getInt(1)); - assertEquals("a_" + i, results.getString(2)); - } - assertFalse(results.next()); - results.close(); - } - } - - @Test public void commitAndRollback() throws Exception { - final String tableName = getTableName(); - - // Disable autoCommit - connection.setAutoCommit(false); - assertFalse(connection.getAutoCommit()); - - 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 varchar(10))"; - assertFalse(stmt.execute(sql)); - - for (int i = 0; i < 10; i++) { - sql = "INSERT INTO " + tableName + " values (" + i + ", '" + i + "')"; - assertEquals(1, stmt.executeUpdate(sql)); - if (i == 4) { - // Rollback after the first 5 updates - connection.rollback(); - } - } - connection.commit(); - - ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName); - assertNotNull(results); - for (int i = 5; i < 10; i++) { - assertTrue(results.next()); - assertEquals(i, results.getInt(1)); - assertEquals(Integer.toString(i), results.getString(1)); - } - assertFalse(results.next()); - results.close(); - } - } -} - -// End InsertTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/MetadataTest.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/MetadataTest.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/MetadataTest.java deleted file mode 100644 index 9c92ec0..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/MetadataTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.math.BigDecimal; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.Statement; -import java.sql.Types; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Test class for metadata operations (parameter, resultset). - */ -public class MetadataTest extends BaseTckTest { - - @Test public void parameterMetadata() throws Exception { - final String tableName = getTableName(); - try (Statement stmt = getConnection().createStatement()) { - assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName)); - String sql = "CREATE TABLE " + tableName + " (pk integer not null primary key, " - + "col1 DECIMAL(10, 5), col2 boolean not null)"; - assertFalse(stmt.execute(sql)); - - String insertSql = "INSERT INTO " + tableName + " values(?, ?, ?)"; - try (PreparedStatement pstmt = getConnection().prepareStatement(insertSql)) { - ParameterMetaData params = pstmt.getParameterMetaData(); - assertEquals(3, params.getParameterCount()); - - assertEquals(Types.INTEGER, params.getParameterType(1)); - assertTrue(params.isSigned(1)); - assertTrue(ParameterMetaData.parameterNoNulls == params.isNullable(1) - || ParameterMetaData.parameterNullableUnknown == params.isNullable(1)); - - assertEquals(Types.DECIMAL, params.getParameterType(2)); - assertTrue(params.isSigned(2)); - assertTrue(ParameterMetaData.parameterNullable == params.isNullable(2) - || ParameterMetaData.parameterNullableUnknown == params.isNullable(2)); - assertEquals(10, params.getPrecision(2)); - assertEquals(5, params.getScale(2)); - - assertEquals(Types.BOOLEAN, params.getParameterType(3)); - assertFalse(params.isSigned(3)); - assertTrue(ParameterMetaData.parameterNoNulls == params.isNullable(3) - || ParameterMetaData.parameterNullableUnknown == params.isNullable(3)); - - // CALCITE-1103 <1.8.0 server mishandled the protobuf translation from BIG_DECIMAL to NUMBER - pstmt.setInt(1, Integer.MAX_VALUE); - pstmt.setBigDecimal(2, new BigDecimal("12345.12345")); - pstmt.setBoolean(3, true); - assertEquals(1, pstmt.executeUpdate()); - - pstmt.setInt(1, Integer.MIN_VALUE); - pstmt.setBigDecimal(2, new BigDecimal("54321.54321")); - pstmt.setBoolean(3, false); - assertEquals(1, pstmt.executeUpdate()); - } - - ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName + " ORDER BY pk"); - assertNotNull(results); - ResultSetMetaData resultMetadata = results.getMetaData(); - // Verify result metadata - assertEquals(3, resultMetadata.getColumnCount()); - - assertTrue(ParameterMetaData.parameterNoNulls == resultMetadata.isNullable(1) - || ParameterMetaData.parameterNullableUnknown == resultMetadata.isNullable(1)); - assertEquals(Types.INTEGER, resultMetadata.getColumnType(1)); - assertTrue(resultMetadata.isSigned(1)); - - assertTrue(ParameterMetaData.parameterNullable == resultMetadata.isNullable(2) - || ParameterMetaData.parameterNullableUnknown == resultMetadata.isNullable(2)); - assertEquals(Types.DECIMAL, resultMetadata.getColumnType(2)); - assertTrue(resultMetadata.isSigned(2)); - assertEquals(10, resultMetadata.getPrecision(2)); - assertEquals(5, resultMetadata.getScale(2)); - - assertTrue(ParameterMetaData.parameterNoNulls == resultMetadata.isNullable(3) - || ParameterMetaData.parameterNullableUnknown == resultMetadata.isNullable(3)); - assertEquals(Types.BOOLEAN, resultMetadata.getColumnType(3)); - assertFalse(resultMetadata.isSigned(3)); - - // Verify the results - assertTrue(results.next()); - assertEquals(Integer.MIN_VALUE, results.getInt(1)); - // CALCITE-1103 protobuf truncated decimal value - BigDecimal buggyDecimalValue = new BigDecimal("54321.00000"); - BigDecimal expectedDecimalValue = new BigDecimal("54321.54321"); - BigDecimal actualDecimalValue = results.getBigDecimal(2); - assertTrue("Unexpected decimal value of " + actualDecimalValue, - expectedDecimalValue.equals(actualDecimalValue) - || buggyDecimalValue.equals(actualDecimalValue)); - assertEquals(false, results.getBoolean(3)); - - assertTrue(results.next()); - assertEquals(Integer.MAX_VALUE, results.getInt(1)); - // CALCITE-1103 protobuf truncated decimal value - buggyDecimalValue = new BigDecimal("12345.00000"); - expectedDecimalValue = new BigDecimal("12345.12345"); - actualDecimalValue = results.getBigDecimal(2); - assertTrue("Unexpected decimal value of " + actualDecimalValue, - expectedDecimalValue.equals(actualDecimalValue) - || buggyDecimalValue.equals(actualDecimalValue)); - assertEquals(true, results.getBoolean(3)); - - assertFalse(results.next()); - } - } -} - -// End MetadataTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/package-info.java ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/package-info.java b/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/package-info.java deleted file mode 100644 index 940a1bd..0000000 --- a/avatica/tck/src/main/java/org/apache/calcite/avatica/tck/tests/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -/** - * Tests for the Avatica compatibility framework. - */ -@PackageMarker -package org.apache.calcite.avatica.tck.tests; - -import org.apache.calcite.avatica.tck.PackageMarker; - -// End package-info.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/resources/META-INF/LICENSE ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/resources/META-INF/LICENSE b/avatica/tck/src/main/resources/META-INF/LICENSE deleted file mode 100644 index 877a48a..0000000 --- a/avatica/tck/src/main/resources/META-INF/LICENSE +++ /dev/null @@ -1,251 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed 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. - - - - - ------------------------------------------------------------------------ - -APACHE CALCITE AVATICA SUBCOMPONENTS: - -The Apache Calcite Avatica project contains subcomponents with separate copyright -notices and license terms. Your use of the source code for the these -subcomponents is subject to the terms and conditions of the following -licenses. - ------------------------------------------------------------------------ - 3-clause BSD license ------------------------------------------------------------------------ - -The Apache Calcite Avatica project bundles HSQLDB, which is available -under the following "3-clause BSD" license: - - Copyright (c) 2001-2016, The HSQL Development Group - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - Neither the name of the HSQL Development Group nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/resources/example_config.yml ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/resources/example_config.yml b/avatica/tck/src/main/resources/example_config.yml deleted file mode 100644 index a6a352b..0000000 --- a/avatica/tck/src/main/resources/example_config.yml +++ /dev/null @@ -1,38 +0,0 @@ -# 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. ---- -# https://repository.apache.org/content/repositories/snapshots/org/apache/calcite/avatica/avatica-tck/1.8.0-SNAPSHOT -tck_jar: /home/user/avatica-tck-1.8.0-SNAPSHOT-shaded.jar - -# Global template, can be overriden in each version. <url> is automatically replaced by the framework -client_url_template: jdbc:avatica:remote:url=<url>;serialization=PROTOBUF - -# Specifies all versions to be tested against one another -versions: - # The user _must_ fill in the port number for the Avatica server for each version - v1.6.0: - # https://repository.apache.org/content/repositories/releases/org/apache/calcite/calcite-avatica/1.6.0/calcite-avatica-1.6.0.jar - client_jar: /home/user/calcite-avatica-1.6.0.jar - server_url: http://localhost:XXXXX - - v1.7.1: - # https://repository.apache.org/content/repositories/releases/org/apache/calcite/avatica/avatica/1.7.1/avatica-1.7.1.jar - client_jar: /home/user/avatica-1.7.1.jar - server_url: http://localhost:XXXXX - - v1.8.0-SNAPSHOT: - # https://repository.apache.org/content/repositories/snapshots/org/apache/calcite/avatica/avatica/1.8.0-SNAPSHOT/ - client_jar: /home/user/avatica-1.8.0-SNAPSHOT.jar - server_url: http://localhost:XXXXX http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/resources/log4j.properties b/avatica/tck/src/main/resources/log4j.properties deleted file mode 100644 index 68a9cc2..0000000 --- a/avatica/tck/src/main/resources/log4j.properties +++ /dev/null @@ -1,24 +0,0 @@ -# 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. - -# Root logger is configured at INFO and is sent to A1 -log4j.rootLogger=INFO, A1 - -# A1 goes to the console -log4j.appender.A1=org.apache.calcite.avatica.tck.shaded.org.apache.log4j.ConsoleAppender - -# Set the pattern for each log message -log4j.appender.A1.layout=org.apache.calcite.avatica.tck.shaded.org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} - %m%n \ No newline at end of file http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/tck/src/main/ruby/test_runner.rb ---------------------------------------------------------------------- diff --git a/avatica/tck/src/main/ruby/test_runner.rb b/avatica/tck/src/main/ruby/test_runner.rb deleted file mode 100755 index e0b9d73..0000000 --- a/avatica/tck/src/main/ruby/test_runner.rb +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env ruby - -# 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. - -require 'logger' -require 'yaml' - -PASSED = "\033[32mPassed\033[0m" -FAILED = "\033[31mFailed\033[0m" - -VERSIONS_KEY = 'versions' -CLIENT_JAR_KEY = 'client_jar' -SERVER_URL_KEY = 'server_url' -CLIENT_URL_TEMPLATE_KEY = 'client_url_template' - -TCK_JAR_KEY = 'tck_jar' - -# Special key for the client URL template to substitute the server's url -URL_REPLACEMENT_HOLDER = '<url>' - -LOG = Logger.new(STDOUT) -LOG.level = Logger::WARN - - -def usage() - puts "usage: test_runner.rb configuration.yml" -end - -def run_test(tck_jar, client, server) - client_jar = client[:config][CLIENT_JAR_KEY] - client_url = client[:config][CLIENT_URL_TEMPLATE_KEY] - server_url = server[:config][SERVER_URL_KEY] - - puts "\nRunning #{client[:name]} against #{server[:name]}" - - if server_url.end_with? 'X' - LOG.error("Fill in the port for server version '#{server_url}' in the YAML configuration file") - return false - end - - # Make a copy here to be sure to not affect other tests - LOG.debug("Updating server url #{server_url} in #{client_url}") - client_url = client_url.gsub(URL_REPLACEMENT_HOLDER, server_url) - - cmd = "java -cp '#{tck_jar}:#{client_jar}' org.apache.calcite.avatica.tck.TestRunner -u '#{client_url}'" - puts "Java command: '#{cmd}'" - success = system(cmd) - - puts "Test of #{client[:name]} against #{server[:name]} " + (success ? PASSED : FAILED) - return success -end - -unless ARGV.size == 1 - usage() - raise ArgumentError.new('YAML configuration file is required as the only argument') -end - -# Parse the configuration file -config_file = ARGV[0] -config = YAML.load_file(config_file) - -# The Avatica TCK jar -tck_jar = config[TCK_JAR_KEY] -if tck_jar.nil? - raise "Configuration file does not contain '#{TCK_JAR_KEY}' key" -end - -# A client url template specified globally, can be overriden in the version -global_url_template = config[CLIENT_URL_TEMPLATE_KEY] - -# Map of version name to jar/configuration -all_versions = config[VERSIONS_KEY] -if all_versions.nil? - raise "Configuration file does not contain '#{VERSIONS_KEY}' key" -end - -# Push down the global client url template to each version when applicable -all_versions.each do |version| - if version.length != 2 - LOG.warn("Unexpected number of arguments for version: #{version.to_s}") - end - version_config = version[1] - if version_config[CLIENT_URL_TEMPLATE_KEY].nil? and not global_url_template.nil? - version_config[CLIENT_URL_TEMPLATE_KEY] = global_url_template - end -end - -# Convert from a hash to an array of pairs -all_versions = all_versions.collect{ |k,v| {:name=>k, :config=>v} } - -# Compute the "identity" mapping as a sanity check -identity_versions = all_versions.collect {|x| [x, x]} - -# Create a cartesian product of the pairs, dropping entries where the pairs are equal -all_pairs = all_versions.product(all_versions).select {|x| x[0][:name] != x[1][:name]} - -puts "Running identity test as a sanity check (client and server at the same version)" - -identity_outcomes = identity_versions.collect{|pair| {:client => pair[0][:name], :server=>pair[1][:name], :result=>run_test(tck_jar, pair[0], pair[1])}} - -puts "\nRunning cross-version tests" - -# Run the TCK against each pair -outcomes = all_pairs.collect{|pair| {:client=>pair[0][:name], :server=>pair[1][:name], :result=>run_test(tck_jar, pair[0], pair[1])}} - -puts "\n-------------------------------------\nSummary:\n\n" - -puts "Identity test scenarios (ran #{identity_outcomes.size})\n\n" -identity_outcomes.each{|outcome| puts "Testing identity for version #{outcome[:client]}: #{(outcome[:result] ? PASSED : FAILED)}"} - -puts "\nAll test scenarios (ran #{all_pairs.size})\n\n" -outcomes.each{|outcome| puts "Testing client #{outcome[:client]} against server #{outcome[:server]}: #{(outcome[:result] ? PASSED : FAILED)}"} http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/cassandra/pom.xml b/cassandra/pom.xml deleted file mode 100644 index 81294e0..0000000 --- a/cassandra/pom.xml +++ /dev/null @@ -1,143 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.calcite</groupId> - <artifactId>calcite</artifactId> - <version>1.13.0-SNAPSHOT</version> - </parent> - - <artifactId>calcite-cassandra</artifactId> - <packaging>jar</packaging> - <version>1.13.0-SNAPSHOT</version> - <name>Calcite Cassandra</name> - <description>Cassandra adapter for Calcite</description> - - <properties> - <top.dir>${project.basedir}/..</top.dir> - </properties> - - <dependencies> - <!-- Sorted by groupId, artifactId; calcite dependencies first. Put versions - in dependencyManagement in the root POM, not here. --> - <dependency> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.calcite</groupId> - <artifactId>calcite-core</artifactId> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.calcite</groupId> - <artifactId>calcite-core</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.calcite</groupId> - <artifactId>calcite-linq4j</artifactId> - </dependency> - - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.datastax.cassandra</groupId> - <artifactId>cassandra-driver-core</artifactId> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <!-- Sorted by groupId, artifactId. Put versions in - pluginManagement in the root POM, not here. --> - <plugin> - <artifactId>maven-dependency-plugin</artifactId> - <version>${maven-dependency-plugin.version}</version> - <executions> - <execution> - <id>analyze</id> - <goals> - <goal>analyze-only</goal> - </goals> - <configuration> - <failOnWarning>true</failOnWarning> - <!-- ignore "unused but declared" warnings --> - <ignoredUnusedDeclaredDependencies> - <ignoredUnusedDeclaredDependency>org.slf4j:slf4j-api</ignoredUnusedDeclaredDependency> - <ignoredUnusedDeclaredDependency>org.slf4j:slf4j-log4j12</ignoredUnusedDeclaredDependency> - </ignoredUnusedDeclaredDependencies> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - </plugin> - <!-- Parent module has the same plugin and does the work of - generating -sources.jar for each project. But without the - plugin declared here, IDEs don't know the sources are - available. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <phase>verify</phase> - <goals> - <goal>jar-no-fork</goal> - <goal>test-jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java ---------------------------------------------------------------------- diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java deleted file mode 100644 index 0c06800..0000000 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraEnumerator.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.adapter.cassandra; - -import org.apache.calcite.linq4j.Enumerator; -import org.apache.calcite.rel.type.RelDataTypeFactory; -import org.apache.calcite.rel.type.RelDataTypeField; -import org.apache.calcite.rel.type.RelDataTypeSystem; -import org.apache.calcite.rel.type.RelProtoDataType; -import org.apache.calcite.sql.type.SqlTypeFactoryImpl; -import org.apache.calcite.sql.type.SqlTypeName; - -import com.datastax.driver.core.DataType; -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Row; - -import java.util.Iterator; -import java.util.List; - -/** Enumerator that reads from a Cassandra column family. */ -class CassandraEnumerator implements Enumerator<Object> { - private Iterator<Row> iterator; - private Row current; - private List<RelDataTypeField> fieldTypes; - - /** Creates a CassandraEnumerator. - * - * @param results Cassandra result set ({@link com.datastax.driver.core.ResultSet}) - * @param protoRowType The type of resulting rows - */ - public CassandraEnumerator(ResultSet results, RelProtoDataType protoRowType) { - this.iterator = results.iterator(); - this.current = null; - - final RelDataTypeFactory typeFactory = - new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); - this.fieldTypes = protoRowType.apply(typeFactory).getFieldList(); - } - - /** Produce the next row from the results - * - * @return A new row from the results - */ - public Object current() { - if (fieldTypes.size() == 1) { - // If we just have one field, produce it directly - return currentRowField(0, fieldTypes.get(0).getType().getSqlTypeName()); - } else { - // Build an array with all fields in this row - Object[] row = new Object[fieldTypes.size()]; - for (int i = 0; i < fieldTypes.size(); i++) { - row[i] = currentRowField(i, fieldTypes.get(i).getType().getSqlTypeName()); - } - - return row; - } - } - - /** Get a field for the current row from the underlying object. - * - * @param index Index of the field within the Row object - * @param typeName Type of the field in this row - */ - private Object currentRowField(int index, SqlTypeName typeName) { - DataType type = current.getColumnDefinitions().getType(index); - if (type == DataType.ascii() || type == DataType.text() || type == DataType.varchar()) { - return current.getString(index); - } else if (type == DataType.cint() || type == DataType.varint()) { - return current.getInt(index); - } else if (type == DataType.bigint()) { - return current.getLong(index); - } else if (type == DataType.cdouble() || type == DataType.cfloat()) { - return current.getDouble(index); - } else if (type == DataType.uuid() || type == DataType.timeuuid()) { - return current.getUUID(index).toString(); - } else { - return null; - } - } - - public boolean moveNext() { - if (iterator.hasNext()) { - current = iterator.next(); - return true; - } else { - return false; - } - } - - public void reset() { - throw new UnsupportedOperationException(); - } - - public void close() { - // Nothing to do here - } -} - -// End CassandraEnumerator.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java ---------------------------------------------------------------------- diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java deleted file mode 100644 index ba8aa9c..0000000 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraFilter.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * 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.adapter.cassandra; - -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptCost; -import org.apache.calcite.plan.RelOptPlanner; -import org.apache.calcite.plan.RelOptUtil; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelCollations; -import org.apache.calcite.rel.RelFieldCollation; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.Filter; -import org.apache.calcite.rel.metadata.RelMetadataQuery; -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rex.RexCall; -import org.apache.calcite.rex.RexInputRef; -import org.apache.calcite.rex.RexLiteral; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.sql.type.SqlTypeName; -import org.apache.calcite.util.Util; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implementation of a {@link org.apache.calcite.rel.core.Filter} - * relational expression in Cassandra. - */ -public class CassandraFilter extends Filter implements CassandraRel { - private final List<String> partitionKeys; - private Boolean singlePartition; - private final List<String> clusteringKeys; - private List<RelFieldCollation> implicitFieldCollations; - private RelCollation implicitCollation; - private String match; - - public CassandraFilter( - RelOptCluster cluster, - RelTraitSet traitSet, - RelNode child, - RexNode condition, - List<String> partitionKeys, - List<String> clusteringKeys, - List<RelFieldCollation> implicitFieldCollations) { - super(cluster, traitSet, child, condition); - - this.partitionKeys = partitionKeys; - this.singlePartition = false; - this.clusteringKeys = new ArrayList<String>(clusteringKeys); - this.implicitFieldCollations = implicitFieldCollations; - - Translator translator = - new Translator(getRowType(), partitionKeys, clusteringKeys, - implicitFieldCollations); - this.match = translator.translateMatch(condition); - this.singlePartition = translator.isSinglePartition(); - this.implicitCollation = translator.getImplicitCollation(); - - assert getConvention() == CassandraRel.CONVENTION; - assert getConvention() == child.getConvention(); - } - - @Override public RelOptCost computeSelfCost(RelOptPlanner planner, - RelMetadataQuery mq) { - return super.computeSelfCost(planner, mq).multiplyBy(0.1); - } - - public CassandraFilter copy(RelTraitSet traitSet, RelNode input, - RexNode condition) { - return new CassandraFilter(getCluster(), traitSet, input, condition, - partitionKeys, clusteringKeys, implicitFieldCollations); - } - - public void implement(Implementor implementor) { - implementor.visitChild(0, getInput()); - implementor.add(null, Collections.singletonList(match)); - } - - /** Check if the filter restricts to a single partition. - * - * @return True if the filter will restrict the underlying to a single partition - */ - public boolean isSinglePartition() { - return singlePartition; - } - - /** Get the resulting collation by the clustering keys after filtering. - * - * @return The implicit collation based on the natural sorting by clustering keys - */ - public RelCollation getImplicitCollation() { - return implicitCollation; - } - - /** Translates {@link RexNode} expressions into Cassandra expression strings. */ - static class Translator { - private final RelDataType rowType; - private final List<String> fieldNames; - private final Set<String> partitionKeys; - private final List<String> clusteringKeys; - private int restrictedClusteringKeys; - private final List<RelFieldCollation> implicitFieldCollations; - - Translator(RelDataType rowType, List<String> partitionKeys, List<String> clusteringKeys, - List<RelFieldCollation> implicitFieldCollations) { - this.rowType = rowType; - this.fieldNames = CassandraRules.cassandraFieldNames(rowType); - this.partitionKeys = new HashSet<String>(partitionKeys); - this.clusteringKeys = clusteringKeys; - this.restrictedClusteringKeys = 0; - this.implicitFieldCollations = implicitFieldCollations; - } - - /** Check if the query spans only one partition. - * - * @return True if the matches translated so far have resulted in a single partition - */ - public boolean isSinglePartition() { - return partitionKeys.isEmpty(); - } - - /** Infer the implicit correlation from the unrestricted clustering keys. - * - * @return The collation of the filtered results - */ - public RelCollation getImplicitCollation() { - // No collation applies if we aren't restricted to a single partition - if (!isSinglePartition()) { - return RelCollations.EMPTY; - } - - // Pull out the correct fields along with their original collations - List<RelFieldCollation> fieldCollations = new ArrayList<RelFieldCollation>(); - for (int i = restrictedClusteringKeys; i < clusteringKeys.size(); i++) { - int fieldIndex = fieldNames.indexOf(clusteringKeys.get(i)); - RelFieldCollation.Direction direction = implicitFieldCollations.get(i).getDirection(); - fieldCollations.add(new RelFieldCollation(fieldIndex, direction)); - } - - return RelCollations.of(fieldCollations); - } - - /** Produce the CQL predicate string for the given condition. - * - * @param condition Condition to translate - * @return CQL predicate string - */ - private String translateMatch(RexNode condition) { - // CQL does not support disjunctions - List<RexNode> disjunctions = RelOptUtil.disjunctions(condition); - if (disjunctions.size() == 1) { - return translateAnd(disjunctions.get(0)); - } else { - throw new AssertionError("cannot translate " + condition); - } - } - - /** Conver the value of a literal to a string. - * - * @param literal Literal to translate - * @return String representation of the literal - */ - private static String literalValue(RexLiteral literal) { - Object value = literal.getValue2(); - StringBuilder buf = new StringBuilder(); - buf.append(value); - return buf.toString(); - } - - /** Translate a conjunctive predicate to a CQL string. - * - * @param condition A conjunctive predicate - * @return CQL string for the predicate - */ - private String translateAnd(RexNode condition) { - List<String> predicates = new ArrayList<String>(); - for (RexNode node : RelOptUtil.conjunctions(condition)) { - predicates.add(translateMatch2(node)); - } - - return Util.toString(predicates, "", " AND ", ""); - } - - /** Translate a binary relation. */ - private String translateMatch2(RexNode node) { - // We currently only use equality, but inequalities on clustering keys - // should be possible in the future - switch (node.getKind()) { - case EQUALS: - return translateBinary("=", "=", (RexCall) node); - case LESS_THAN: - return translateBinary("<", ">", (RexCall) node); - case LESS_THAN_OR_EQUAL: - return translateBinary("<=", ">=", (RexCall) node); - case GREATER_THAN: - return translateBinary(">", "<", (RexCall) node); - case GREATER_THAN_OR_EQUAL: - return translateBinary(">=", "<=", (RexCall) node); - default: - throw new AssertionError("cannot translate " + node); - } - } - - /** Translates a call to a binary operator, reversing arguments if - * necessary. */ - private String translateBinary(String op, String rop, RexCall call) { - final RexNode left = call.operands.get(0); - final RexNode right = call.operands.get(1); - String expression = translateBinary2(op, left, right); - if (expression != null) { - return expression; - } - expression = translateBinary2(rop, right, left); - if (expression != null) { - return expression; - } - throw new AssertionError("cannot translate op " + op + " call " + call); - } - - /** Translates a call to a binary operator. Returns null on failure. */ - private String translateBinary2(String op, RexNode left, RexNode right) { - switch (right.getKind()) { - case LITERAL: - break; - default: - return null; - } - final RexLiteral rightLiteral = (RexLiteral) right; - switch (left.getKind()) { - case INPUT_REF: - final RexInputRef left1 = (RexInputRef) left; - String name = fieldNames.get(left1.getIndex()); - return translateOp2(op, name, rightLiteral); - case CAST: - // FIXME This will not work in all cases (for example, we ignore string encoding) - return translateBinary2(op, ((RexCall) left).operands.get(0), right); - default: - return null; - } - } - - /** Combines a field name, operator, and literal to produce a predicate string. */ - private String translateOp2(String op, String name, RexLiteral right) { - // In case this is a key, record that it is now restricted - if (op.equals("=")) { - partitionKeys.remove(name); - if (clusteringKeys.contains(name)) { - restrictedClusteringKeys++; - } - } - - Object value = literalValue(right); - String valueString = value.toString(); - if (value instanceof String) { - SqlTypeName typeName = rowType.getField(name, true, false).getType().getSqlTypeName(); - if (typeName != SqlTypeName.CHAR) { - valueString = "'" + valueString + "'"; - } - } - return name + " " + op + " " + valueString; - } - } -} - -// End CassandraFilter.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraLimit.java ---------------------------------------------------------------------- diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraLimit.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraLimit.java deleted file mode 100644 index cca7e19..0000000 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraLimit.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.adapter.cassandra; - -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptCost; -import org.apache.calcite.plan.RelOptPlanner; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.RelWriter; -import org.apache.calcite.rel.SingleRel; -import org.apache.calcite.rel.metadata.RelMetadataQuery; -import org.apache.calcite.rex.RexLiteral; -import org.apache.calcite.rex.RexNode; - -import java.util.List; - -/** - * Implementation of limits in Cassandra. - */ -public class CassandraLimit extends SingleRel implements CassandraRel { - public final RexNode offset; - public final RexNode fetch; - - public CassandraLimit(RelOptCluster cluster, RelTraitSet traitSet, - RelNode input, RexNode offset, RexNode fetch) { - super(cluster, traitSet, input); - this.offset = offset; - this.fetch = fetch; - assert getConvention() == input.getConvention(); - } - - @Override public RelOptCost computeSelfCost(RelOptPlanner planner, - RelMetadataQuery mq) { - // We do this so we get the limit for free - return planner.getCostFactory().makeZeroCost(); - } - - @Override public CassandraLimit copy(RelTraitSet traitSet, List<RelNode> newInputs) { - return new CassandraLimit(getCluster(), traitSet, sole(newInputs), offset, fetch); - } - - public void implement(Implementor implementor) { - implementor.visitChild(0, getInput()); - if (offset != null) { implementor.offset = RexLiteral.intValue(offset); } - if (fetch != null) { implementor.fetch = RexLiteral.intValue(fetch); } - } - - public RelWriter explainTerms(RelWriter pw) { - super.explainTerms(pw); - pw.itemIf("offset", offset, offset != null); - pw.itemIf("fetch", fetch, fetch != null); - return pw; - } -} - -// End CassandraLimit.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraMethod.java ---------------------------------------------------------------------- diff --git a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraMethod.java b/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraMethod.java deleted file mode 100644 index b2035e5..0000000 --- a/cassandra/src/main/java/org/apache/calcite/adapter/cassandra/CassandraMethod.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.adapter.cassandra; - -import org.apache.calcite.linq4j.tree.Types; - -import com.google.common.collect.ImmutableMap; - -import java.lang.reflect.Method; -import java.util.List; - -/** - * Builtin methods in the Cassandra adapter. - */ -public enum CassandraMethod { - CASSANDRA_QUERYABLE_QUERY(CassandraTable.CassandraQueryable.class, "query", - List.class, List.class, List.class, List.class, Integer.class, Integer.class); - - public final Method method; - - public static final ImmutableMap<Method, CassandraMethod> MAP; - - static { - final ImmutableMap.Builder<Method, CassandraMethod> builder = - ImmutableMap.builder(); - for (CassandraMethod value : CassandraMethod.values()) { - builder.put(value.method, value); - } - MAP = builder.build(); - } - - CassandraMethod(Class clazz, String methodName, Class... argumentTypes) { - this.method = Types.lookupMethod(clazz, methodName, argumentTypes); - } -} - -// End CassandraMethod.java
