You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/11/14 22:32:58 UTC
[50/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java b/avatica/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
index 3a5994d..d1396b1 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java
@@ -14,10 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
-import java.sql.*;
-import java.util.*;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.List;
/**
* Implementation of {@link java.sql.Statement}
@@ -368,7 +372,7 @@ public abstract class AvaticaStatement
* <p>The default implementation returns the empty list, because non-prepared
* statements have no parameters.</p>
*
- * @see net.hydromatic.avatica.AvaticaConnection.Trojan#getParameterValues(AvaticaStatement)
+ * @see org.apache.calcite.avatica.AvaticaConnection.Trojan#getParameterValues(AvaticaStatement)
*/
protected List<Object> getParameterValues() {
return Collections.emptyList();
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java b/avatica/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
index b70c24c..16501a2 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java
@@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import static net.hydromatic.avatica.ConnectionConfigImpl.*;
+import static org.apache.calcite.avatica.ConnectionConfigImpl.PropEnv;
+import static org.apache.calcite.avatica.ConnectionConfigImpl.parse;
/**
* Enumeration of Avatica's built-in connection properties.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ByteString.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ByteString.java b/avatica/src/main/java/org/apache/calcite/avatica/ByteString.java
index 7bfdcba..03f04b5 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ByteString.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ByteString.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.io.Serializable;
import java.util.Arrays;
@@ -52,13 +52,11 @@ public class ByteString implements Comparable<ByteString>, Serializable {
this.bytes = bytes;
}
- @Override
- public int hashCode() {
+ @Override public int hashCode() {
return Arrays.hashCode(bytes);
}
- @Override
- public boolean equals(Object obj) {
+ @Override public boolean equals(Object obj) {
return this == obj
|| obj instanceof ByteString
&& Arrays.equals(bytes, ((ByteString) obj).bytes);
@@ -83,8 +81,7 @@ public class ByteString implements Comparable<ByteString>, Serializable {
*
* @return Hexadecimal string
*/
- @Override
- public String toString() {
+ @Override public String toString() {
return toString(16);
}
@@ -141,8 +138,7 @@ public class ByteString implements Comparable<ByteString>, Serializable {
"CloneDoesntCallSuperClone",
"CloneDoesntDeclareCloneNotSupportedException"
})
- @Override
- public Object clone() {
+ @Override public Object clone() {
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Casing.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Casing.java b/avatica/src/main/java/org/apache/calcite/avatica/Casing.java
index db9e42d..763c514 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Casing.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Casing.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
/** Policy for converting case of identifiers before storing them.
*
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java b/avatica/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java
index 598a604..a1997ba 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java
@@ -14,10 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.lang.reflect.Type;
-import java.sql.*;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSetMetaData;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -25,7 +29,7 @@ import java.util.Map;
/**
* Metadata for a column.
- * (Compare with {@link java.sql.ResultSetMetaData}.)
+ * (Compare with {@link ResultSetMetaData}.)
*/
public class ColumnMetaData {
public final int ordinal; // 0-based
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java b/avatica/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java
index c2d68ac..d19815a 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.sql.SQLException;
import java.util.Map;
@@ -33,11 +33,15 @@ import java.util.Properties;
* <li>use of regular {@link Properties} for compatibility with the JDBC API
* (replaces Mondrian's use of its own order-preserving and case-insensitive
* PropertyList, found in Util.java at link above)</li>
+ *
* <li>ability to pass to {@link #parse} a pre-existing Properties object into
* which properties are to be parsed, possibly overriding prior values</li>
- * <li>use of {@link SQLException}s rather than unchecked {@link
- * RuntimeException}s</li>
+ *
+ * <li>use of {@link SQLException}s rather than unchecked
+ * {@link RuntimeException}s</li>
+ *
* <li>static members for parsing and creating connect strings</li>
+ *
* </ul>
*
* <p>ConnectStringParser has a private constructor. Callers use the static
@@ -224,7 +228,7 @@ public class ConnectStringParser {
} else {
throw new SQLException(
"quoted value ended too soon, at position " + i
- + " in '" + s + "'");
+ + " in '" + s + "'");
}
} else {
String value;
@@ -275,8 +279,8 @@ public class ConnectStringParser {
}
throw new SQLException(
"Connect string '" + s
- + "' contains unterminated quoted value '"
- + valueBuf.toString() + "'");
+ + "' contains unterminated quoted value '"
+ + valueBuf.toString() + "'");
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
index d63e3f3..a799930 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
/**
* Connection configuration.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
index f406da2..c2c7b45 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
@@ -39,7 +39,7 @@ public class ConnectionConfigImpl implements ConnectionConfig {
/** Converts a {@link Properties} object containing (name, value)
* pairs into a map whose keys are
- * {@link net.hydromatic.avatica.InternalProperty} objects.
+ * {@link org.apache.calcite.avatica.InternalProperty} objects.
*
* <p>Matching is case-insensitive. Throws if a property is not known.
* If a property occurs more than once, takes the last occurrence.</p>
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/ConnectionProperty.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionProperty.java b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionProperty.java
index 5fcdc50..bfdc4ad 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/ConnectionProperty.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/ConnectionProperty.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.util.Properties;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Cursor.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Cursor.java b/avatica/src/main/java/org/apache/calcite/avatica/Cursor.java
index 9207578..b8b42c3 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Cursor.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Cursor.java
@@ -14,19 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
-import java.io.*;
+import java.io.Closeable;
+import java.io.InputStream;
+import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
-import java.sql.*;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
/**
* Interface to an iteration that is similar to, and can easily support,
- * a JDBC {@link ResultSet}, but is simpler to implement.
+ * a JDBC {@link java.sql.ResultSet}, but is simpler to implement.
*/
public interface Cursor extends Closeable {
/**
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/DriverVersion.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/DriverVersion.java b/avatica/src/main/java/org/apache/calcite/avatica/DriverVersion.java
index 1f124ee..15c966a 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/DriverVersion.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/DriverVersion.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.io.IOException;
import java.io.InputStream;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Handler.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Handler.java b/avatica/src/main/java/org/apache/calcite/avatica/Handler.java
index 0363f4b..831e66d 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Handler.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Handler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.sql.SQLException;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/HandlerImpl.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/HandlerImpl.java b/avatica/src/main/java/org/apache/calcite/avatica/HandlerImpl.java
index 411afd8..c2e6c1a 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/HandlerImpl.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/HandlerImpl.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.sql.SQLException;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Helper.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Helper.java b/avatica/src/main/java/org/apache/calcite/avatica/Helper.java
index 8b55c78..3c78b41 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Helper.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Helper.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.sql.SQLException;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/InternalProperty.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/InternalProperty.java b/avatica/src/main/java/org/apache/calcite/avatica/InternalProperty.java
index bee4b30..ab5f455 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/InternalProperty.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/InternalProperty.java
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
-import net.hydromatic.avatica.ConnectionProperty.Type;
+import org.apache.calcite.avatica.ConnectionProperty.Type;
-import java.util.*;
+import java.util.Map;
/**
* Definitions of properties that drive the behavior of
- * {@link net.hydromatic.avatica.AvaticaDatabaseMetaData}.
+ * {@link org.apache.calcite.avatica.AvaticaDatabaseMetaData}.
*/
public enum InternalProperty {
/** Whether identifiers are matched case-sensitively. */
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Meta.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Meta.java b/avatica/src/main/java/org/apache/calcite/avatica/Meta.java
index 4197b76..c552d4e 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Meta.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Meta.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
import java.sql.ResultSet;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/Quoting.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/Quoting.java b/avatica/src/main/java/org/apache/calcite/avatica/Quoting.java
index 8f49f6c..b73f19c 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/Quoting.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/Quoting.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
/** Syntax for quoting identifiers in SQL statements. */
public enum Quoting {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java b/avatica/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
index 70e119f..1fcca97 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
@@ -14,10 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica;
-
-import java.sql.*;
-import java.util.*;
+package org.apache.calcite.avatica;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -34,8 +42,8 @@ import java.util.logging.Logger;
*
* <p>The provider must implement:</p>
* <ul>
- * <li>{@link net.hydromatic.avatica.Meta#prepare(AvaticaStatement, String)}</li>
- * <li>{@link net.hydromatic.avatica.Meta#createCursor(AvaticaResultSet)}</li>
+ * <li>{@link org.apache.calcite.avatica.Meta#prepare(AvaticaStatement, String)}
+ * <li>{@link org.apache.calcite.avatica.Meta#createCursor(AvaticaResultSet)}
* </ul>
*/
public abstract class UnregisteredDriver implements java.sql.Driver {
@@ -78,12 +86,12 @@ public abstract class UnregisteredDriver implements java.sql.Driver {
protected String getFactoryClassName(JdbcVersion jdbcVersion) {
switch (jdbcVersion) {
case JDBC_30:
- return "net.hydromatic.avatica.AvaticaFactoryJdbc3Impl";
+ return "org.apache.calcite.avatica.AvaticaFactoryJdbc3Impl";
case JDBC_40:
- return "net.hydromatic.avatica.AvaticaJdbc40Factory";
+ return "org.apache.calcite.avatica.AvaticaJdbc40Factory";
case JDBC_41:
default:
- return "net.hydromatic.avatica.AvaticaJdbc41Factory";
+ return "org.apache.calcite.avatica.AvaticaJdbc41Factory";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/main/java/org/apache/calcite/avatica/package-info.java
----------------------------------------------------------------------
diff --git a/avatica/src/main/java/org/apache/calcite/avatica/package-info.java b/avatica/src/main/java/org/apache/calcite/avatica/package-info.java
index 3b8f3eb..7aad356 100644
--- a/avatica/src/main/java/org/apache/calcite/avatica/package-info.java
+++ b/avatica/src/main/java/org/apache/calcite/avatica/package-info.java
@@ -18,6 +18,6 @@
/**
* Avatica JDBC framework.
*/
-package net.hydromatic.avatica;
+package org.apache.calcite.avatica;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/test/java/org/apache/calcite/avatica/test/AvaticaSuite.java
----------------------------------------------------------------------
diff --git a/avatica/src/test/java/org/apache/calcite/avatica/test/AvaticaSuite.java b/avatica/src/test/java/org/apache/calcite/avatica/test/AvaticaSuite.java
index c83f40e..fcb3f16 100644
--- a/avatica/src/test/java/org/apache/calcite/avatica/test/AvaticaSuite.java
+++ b/avatica/src/test/java/org/apache/calcite/avatica/test/AvaticaSuite.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica.test;
+package org.apache.calcite.avatica.test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/test/java/org/apache/calcite/avatica/test/ConnectStringParserTest.java
----------------------------------------------------------------------
diff --git a/avatica/src/test/java/org/apache/calcite/avatica/test/ConnectStringParserTest.java b/avatica/src/test/java/org/apache/calcite/avatica/test/ConnectStringParserTest.java
index bdf7245..cdc8d8a 100644
--- a/avatica/src/test/java/org/apache/calcite/avatica/test/ConnectStringParserTest.java
+++ b/avatica/src/test/java/org/apache/calcite/avatica/test/ConnectStringParserTest.java
@@ -14,16 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.avatica.test;
+package org.apache.calcite.avatica.test;
-import net.hydromatic.avatica.ConnectStringParser;
+import org.apache.calcite.avatica.ConnectStringParser;
import org.junit.Test;
import java.sql.SQLException;
import java.util.Properties;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
/**
* Unit test for JDBC connect string parser, {@link ConnectStringParser}. The
@@ -69,8 +71,7 @@ public class ConnectStringParserTest {
*/
@Test public void testComplexStrings() throws Throwable {
Properties props =
- ConnectStringParser.parse(
- "normalProp=value;"
+ ConnectStringParser.parse("normalProp=value;"
+ "emptyValue=;"
+ " spaceBeforeProp=abc;"
+ " spaceBeforeAndAfterProp =def;"
@@ -226,14 +227,11 @@ public class ConnectStringParserTest {
Throwable e,
String expectedPattern) {
if (e == null) {
- fail(
- "Expected an error which matches pattern '" + expectedPattern
- + "'");
+ fail("Expected an error which matches pattern '" + expectedPattern + "'");
}
String msg = e.toString();
if (!msg.matches(expectedPattern)) {
- fail(
- "Got a different error '" + msg + "' than expected '"
+ fail("Got a different error '" + msg + "' than expected '"
+ expectedPattern + "'");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/avatica/src/test/java/org/apache/calcite/avatica/test/package-info.java
----------------------------------------------------------------------
diff --git a/avatica/src/test/java/org/apache/calcite/avatica/test/package-info.java b/avatica/src/test/java/org/apache/calcite/avatica/test/package-info.java
index 184aef6..7680316 100644
--- a/avatica/src/test/java/org/apache/calcite/avatica/test/package-info.java
+++ b/avatica/src/test/java/org/apache/calcite/avatica/test/package-info.java
@@ -18,6 +18,6 @@
/**
* Avatica tests.
*/
-package net.hydromatic.avatica.test;
+package org.apache.calcite.avatica.test;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 116fab2..1c5527c 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -58,7 +58,7 @@ limitations under the License.
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
- <include>net/hydromatic/optiq/test/OptiqSuite.java</include>
+ <include>org/apache/calcite/test/CalciteSuite.java</include>
</includes>
<threadCount>1</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
@@ -78,7 +78,7 @@ limitations under the License.
<configuration>
<sourceDirectory>${project.build.directory}/generated-sources/fmpp</sourceDirectory>
<includes>
- <include>**/CombinedParser.jj</include>
+ <include>**/Parser.jj</include>
</includes>
<lookAhead>2</lookAhead>
<isStatic>false</isStatic>
@@ -95,7 +95,7 @@ limitations under the License.
<goal>generate-sources</goal>
</goals>
<configuration>
- <packageName>org.eigenbase.resource</packageName>
+ <packageName>org.apache.calcite.runtime</packageName>
</configuration>
</execution>
</executions>
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp
index b45cd3a..d480488 100644
--- a/core/src/main/codegen/config.fmpp
+++ b/core/src/main/codegen/config.fmpp
@@ -17,7 +17,7 @@
# allow clients to extend Calcite's SQL parser to support application specific
# SQL statements, literals or data types.
#
-# Calcite's parser grammar file (CombinedParser.jj) is written in javacc
+# Calcite's parser grammar file (Parser.jj) is written in javacc
# (http://javacc.java.net/) with Freemarker (http://freemarker.org/) variables
# to allow clients to:
# 1. have custom parser implementation class and package name.
@@ -29,17 +29,17 @@
# 3. add new keywords to support custom SQL constructs added as part of (2).
# 4. add import statements needed by inserted custom parser implementations.
#
-# Parser template file (CombinerParser.jj) along with this file are packaged as
+# Parser template file (Parser.jj) along with this file are packaged as
# part of the calcite-core-<version>.jar under "codegen" directory.
data: {
parser: {
# Generated parser implementation package and class name.
- package: "org.eigenbase.sql.parser.impl",
+ package: "org.apache.calcite.sql.parser.impl",
class: "SqlParserImpl",
# List of additional classes and packages to import.
- # Example. "org.eigenbase.sql.*", "java.util.List".
+ # Example. "org.apache.calcite.sql.*", "java.util.List".
imports: [
]
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 54b6df2..de98351 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -16,7 +16,7 @@
*/
<@pp.dropOutputFile />
-<@pp.changeOutputFile name="javacc/CombinedParser.jj" />
+<@pp.changeOutputFile name="javacc/Parser.jj" />
options {
STATIC = false;
@@ -33,41 +33,85 @@ package ${parser.package};
import ${importStr};
</#list>
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.trace.EigenbaseTrace;
-import org.eigenbase.util.BitString;
-import org.eigenbase.util14.DateTimeUtil;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.resource.*;
-import net.hydromatic.avatica.Casing;
+import org.apache.calcite.avatica.Casing;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.runtime.CalciteContextException;
+import org.apache.calcite.sql.JoinConditionType;
+import org.apache.calcite.sql.JoinType;
+import org.apache.calcite.sql.SqlBinaryOperator;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCharStringLiteral;
+import org.apache.calcite.sql.SqlCollation;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlDateLiteral;
+import org.apache.calcite.sql.SqlDelete;
+import org.apache.calcite.sql.SqlDynamicParam;
+import org.apache.calcite.sql.SqlExplain;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlInsert;
+import org.apache.calcite.sql.SqlIntervalLiteral;
+import org.apache.calcite.sql.SqlIntervalQualifier;
+import org.apache.calcite.sql.SqlJdbcFunctionCall;
+import org.apache.calcite.sql.SqlJoin;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlMerge;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlNumericLiteral;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlOrderBy;
+import org.apache.calcite.sql.SqlPostfixOperator;
+import org.apache.calcite.sql.SqlPrefixOperator;
+import org.apache.calcite.sql.SqlSampleSpec;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlSelectKeyword;
+import org.apache.calcite.sql.SqlSetOption;
+import org.apache.calcite.sql.SqlTimeLiteral;
+import org.apache.calcite.sql.SqlTimestampLiteral;
+import org.apache.calcite.sql.SqlUpdate;
+import org.apache.calcite.sql.SqlUtil;
+import org.apache.calcite.sql.SqlWindow;
+import org.apache.calcite.sql.SqlWith;
+import org.apache.calcite.sql.SqlWithItem;
+import org.apache.calcite.sql.fun.SqlCase;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.fun.SqlTrimFunction;
+import org.apache.calcite.sql.parser.SqlAbstractParserImpl;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParserImplFactory;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.parser.SqlParserUtil;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.trace.CalciteTrace;
+import org.apache.calcite.util.DateTimeUtil;
import com.google.common.collect.ImmutableList;
import java.io.Reader;
-import java.math.*;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
-import java.util.logging.Logger;
import java.util.logging.Level;
+import java.util.logging.Logger;
-import static org.eigenbase.util.Static.RESOURCE;
+import static org.apache.calcite.util.Static.RESOURCE;
/**
- * SQL parser, generated from Parser.jj and CommonParser.jj by JavaCC.
+ * SQL parser, generated from Parser.jj by JavaCC.
*
* <p>The public wrapper for this parser is {@link SqlParser}.
*/
public class ${parser.class} extends SqlAbstractParserImpl
{
- private static final Logger LOGGER = EigenbaseTrace.getParserTracer();
+ private static final Logger LOGGER = CalciteTrace.getParserTracer();
// Can't use quoted literal because of a bug in how JavaCC translates
// backslash-backslash.
@@ -437,15 +481,15 @@ JAVACODE SqlParseException convertException(Throwable ex)
int column = Integer.parseInt(matcher.group(2));
pos = new SqlParserPos(line, column, line, column);
}
- } else if (ex instanceof org.eigenbase.util.EigenbaseContextException) {
- // EigenbaseContextException is the standard wrapper for exceptions
+ } else if (ex instanceof CalciteContextException) {
+ // CalciteContextException is the standard wrapper for exceptions
// produced by the validator, but in the parser, the standard is
// SqlParseException; so, strip it away. In case you were wondering,
- // the EigenbaseContextException appears because the parser
+ // the CalciteContextException appears because the parser
// occasionally calls into validator-style code such as
// SqlSpecialOperator.reduceExpr.
- org.eigenbase.util.EigenbaseContextException ece =
- (org.eigenbase.util.EigenbaseContextException) ex;
+ CalciteContextException ece =
+ (CalciteContextException) ex;
pos = new SqlParserPos(
ece.getPosLine(),
ece.getPosColumn(),
@@ -666,9 +710,7 @@ SqlNode ParenthesizedExpression(ExprContext exprContext) :
/**
* Parses a parenthesized query or comma-list of row expressions.
*
- *<p>
- *
- * REVIEW jvs 8-Feb-2004: There's a small hole in this production. It can be
+ * <p>REVIEW jvs 8-Feb-2004: There's a small hole in this production. It can be
* used to construct something like
*
* <code>WHERE x IN (select count(*) from t where c=d,5)</code>,
@@ -732,10 +774,8 @@ SqlNodeList ParenthesizedQueryOrCommaList(
/**
* Parses function parameter lists including DISTINCT keyword recognition
*
- *<p>
- *
- * This is pretty much the same as ParenthesizedQueryOrCommaList but allows the
- * DISTINCT keyword to follow the left paren and not be followed by a comma.
+ * <p>This is pretty much the same as ParenthesizedQueryOrCommaList but allows
+ * the DISTINCT keyword to follow the left paren and not be followed by a comma.
*/
List FunctionParameterList(
ExprContext exprContext) :
@@ -3919,9 +3959,7 @@ SqlNode BuiltinFunctionCall() :
* Parses a call to a named function (could be a builtin with regular
* syntax, or else a UDF).
*
- *<p>
- *
- * NOTE: every UDF has two names: an <em>invocation name</em> and a
+ * <p>NOTE: every UDF has two names: an <em>invocation name</em> and a
* <em>specific name</em>. Normally, function calls are resolved via overload
* resolution and invocation names. The SPECIFIC prefix allows overload
* resolution to be bypassed. Note that usage of the SPECIFIC prefix in
@@ -3929,9 +3967,7 @@ SqlNode BuiltinFunctionCall() :
* view definitions to permanently bind references to a particular function
* after the overload resolution performed by view creation.
*
- *<p>
- *
- * TODO jvs 25-Mar-2005: Once we have SQL-Flagger support, flag SPECIFIC
+ * <p>TODO jvs 25-Mar-2005: Once we have SQL-Flagger support, flag SPECIFIC
* as non-standard.
*/
SqlNode NamedFunctionCall() :
@@ -4916,9 +4952,7 @@ SqlPostfixOperator PostfixRowOperator() :
* of this parser can use this as a base for implementing the
* NonReservedKeyWord() production.
*
- *<p>
- *
- * When adding keywords to this list, be sure that they are not reserved
+ * <p>When adding keywords to this list, be sure that they are not reserved
* by the SQL:2003 standard (see productions for "non-reserved word"
* and "reserved word" in reference below).
*
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/DataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/DataContext.java b/core/src/main/java/org/apache/calcite/DataContext.java
index 1f92631..3d5203f 100644
--- a/core/src/main/java/org/apache/calcite/DataContext.java
+++ b/core/src/main/java/org/apache/calcite/DataContext.java
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq;
+package org.apache.calcite;
-import net.hydromatic.linq4j.QueryProvider;
-import net.hydromatic.linq4j.expressions.Expressions;
-import net.hydromatic.linq4j.expressions.ParameterExpression;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.sql.advise.SqlAdvisor;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-
-import org.eigenbase.sql.advise.SqlAdvisor;
-import org.eigenbase.util.Util;
+import com.google.common.base.CaseFormat;
import java.lang.reflect.Modifier;
import java.util.TimeZone;
@@ -90,7 +90,8 @@ public interface DataContext {
Variable(String camelName, Class clazz) {
this.camelName = camelName;
this.clazz = clazz;
- assert camelName.equals(Util.toCamelCase(name()));
+ assert camelName.equals(
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()));
}
/** Returns the value of this variable in a given data context. */
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/Demo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/Demo.java b/core/src/main/java/org/apache/calcite/Demo.java
index 03ea39e..27f65fe 100644
--- a/core/src/main/java/org/apache/calcite/Demo.java
+++ b/core/src/main/java/org/apache/calcite/Demo.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq;
+package org.apache.calcite;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java b/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
index b97bb18..6bfe42f 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/ArrayTable.java
@@ -14,25 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.clone;
-
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.Primitive;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.AbstractTableQueryable;
-import net.hydromatic.optiq.impl.java.AbstractQueryableTable;
-import net.hydromatic.optiq.util.BitSets;
-
-import org.eigenbase.reltype.*;
-import org.eigenbase.util.*;
+package org.apache.calcite.adapter.clone;
+
+import org.apache.calcite.adapter.java.AbstractQueryableTable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.tree.Primitive;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.schema.Statistics;
+import org.apache.calcite.schema.impl.AbstractTableQueryable;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.Pair;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.List;
/**
* Implementation of table that reads rows from column stores, one per column.
@@ -185,8 +195,7 @@ class ArrayTable extends AbstractQueryableTable {
cardinality);
}
- @Override
- public String toString() {
+ @Override public String toString() {
return "Column(representation=" + representation
+ ", value=" + representation.toString(dataSet) + ")";
}
@@ -453,8 +462,7 @@ class ArrayTable extends AbstractQueryableTable {
public StringDictionary() {
}
- @Override
- public String toString() {
+ @Override public String toString() {
return "StringDictionary()";
}
@@ -591,8 +599,7 @@ class ArrayTable extends AbstractQueryableTable {
this.signed = signed;
}
- @Override
- public String toString() {
+ @Override public String toString() {
return "BitSlicedPrimitiveArray(ordinal=" + ordinal
+ ", bitCount=" + bitCount
+ ", primitive=" + primitive
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/clone/CloneSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/clone/CloneSchema.java b/core/src/main/java/org/apache/calcite/adapter/clone/CloneSchema.java
index 2f37b43..2f996b9 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/CloneSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/CloneSchema.java
@@ -14,19 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.clone;
+package org.apache.calcite.adapter.clone;
-import net.hydromatic.avatica.ColumnMetaData;
-
-import net.hydromatic.linq4j.*;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.AbstractSchema;
-import net.hydromatic.optiq.impl.java.*;
-import net.hydromatic.optiq.impl.jdbc.JdbcSchema;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-
-import org.eigenbase.reltype.RelProtoDataType;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.QueryableTable;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.SchemaFactory;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.impl.AbstractSchema;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
@@ -36,7 +40,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import static net.hydromatic.optiq.impl.MaterializedViewTable.MATERIALIZATION_CONNECTION;
+import static org.apache.calcite.schema.impl.MaterializedViewTable.MATERIALIZATION_CONNECTION;
/**
* Schema that contains in-memory copies of tables from a JDBC schema.
@@ -58,8 +62,7 @@ public class CloneSchema extends AbstractSchema {
this.sourceSchema = sourceSchema;
}
- @Override
- protected Map<String, Table> getTableMap() {
+ @Override protected Map<String, Table> getTableMap() {
final Map<String, Table> map = new LinkedHashMap<String, Table>();
for (String name : sourceSchema.getTableNames()) {
final Table table = sourceSchema.getTable(name);
@@ -77,7 +80,7 @@ public class CloneSchema extends AbstractSchema {
final Queryable<Object> queryable =
sourceTable.asQueryable(queryProvider, sourceSchema, name);
final JavaTypeFactory typeFactory =
- ((OptiqConnection) queryProvider).getTypeFactory();
+ ((CalciteConnection) queryProvider).getTypeFactory();
return createCloneTable(typeFactory, Schemas.proto(sourceTable), null,
queryable);
}
@@ -114,7 +117,7 @@ public class CloneSchema extends AbstractSchema {
}
/** Schema factory that creates a
- * {@link net.hydromatic.optiq.impl.clone.CloneSchema}.
+ * {@link org.apache.calcite.adapter.clone.CloneSchema}.
* This allows you to create a clone schema inside a model.json file.
*
* <pre>{@code
@@ -125,7 +128,7 @@ public class CloneSchema extends AbstractSchema {
* {
* name: 'FOODMART_CLONE',
* type: 'custom',
- * factory: 'net.hydromatic.optiq.impl.clone.CloneSchema$Factory',
+ * factory: 'org.apache.calcite.adapter.clone.CloneSchema$Factory',
* operand: {
* jdbcDriver: 'com.mysql.jdbc.Driver',
* jdbcUrl: 'jdbc:mysql://localhost/foodmart',
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java b/core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java
index 63a7ba7..1338fce 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java
@@ -14,28 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.clone;
-
-import net.hydromatic.avatica.ColumnMetaData;
-
-import net.hydromatic.linq4j.Enumerable;
-import net.hydromatic.linq4j.Ord;
-import net.hydromatic.linq4j.expressions.Primitive;
-import net.hydromatic.linq4j.function.Function1;
-import net.hydromatic.linq4j.function.Functions;
-
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeField;
-import org.eigenbase.reltype.RelProtoDataType;
-import org.eigenbase.util14.DateTimeUtil;
+package org.apache.calcite.adapter.clone;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.function.Functions;
+import org.apache.calcite.linq4j.tree.Primitive;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.util.DateTimeUtil;
import java.lang.reflect.Type;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
-import java.util.*;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* Column loader.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/clone/ListTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/clone/ListTable.java b/core/src/main/java/org/apache/calcite/adapter/clone/ListTable.java
index 34b6abd..c07ea0a 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/ListTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/ListTable.java
@@ -14,20 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.impl.clone;
+package org.apache.calcite.adapter.clone;
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.Expression;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.java.AbstractQueryableTable;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeFactory;
-import org.eigenbase.reltype.RelProtoDataType;
+import org.apache.calcite.adapter.java.AbstractQueryableTable;
+import org.apache.calcite.linq4j.AbstractQueryable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.schema.Statistics;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
/**
* Implementation of table that reads rows from a read-only list and returns
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/clone/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/clone/package-info.java b/core/src/main/java/org/apache/calcite/adapter/clone/package-info.java
index 1c29715..eef12e2 100644
--- a/core/src/main/java/org/apache/calcite/adapter/clone/package-info.java
+++ b/core/src/main/java/org/apache/calcite/adapter/clone/package-info.java
@@ -18,6 +18,6 @@
/**
* Provides utility classes.
*/
-package net.hydromatic.optiq.impl.clone;
+package org.apache.calcite.adapter.clone;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggAddContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggAddContext.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggAddContext.java
index 6d8c4c1..a66e2d7 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggAddContext.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggAddContext.java
@@ -14,25 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import net.hydromatic.linq4j.expressions.Expression;
-
-import org.eigenbase.rex.RexNode;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.rex.RexNode;
import java.util.List;
/**
- * Information for a call to {@link net.hydromatic.optiq.rules.java.AggImplementor#implementAdd(AggContext, AggAddContext)}.
- * Typically, the aggregation implementation will use {@link #arguments()}
+ * Information for a call to
+ * {@link org.apache.calcite.adapter.enumerable.AggImplementor#implementAdd(AggContext, AggAddContext)}.
+ *
+ * <p>Typically, the aggregation implementation will use {@link #arguments()}
* or {@link #rexArguments()} to update aggregate value.
*/
public interface AggAddContext extends AggResultContext {
/**
- * Returns {@link org.eigenbase.rex.RexNode} representation of arguments.
+ * Returns {@link org.apache.calcite.rex.RexNode} representation of arguments.
* This can be useful for manual translation of required arguments with
* different {@link NullPolicy}.
- * @return {@link org.eigenbase.rex.RexNode} representation of arguments
+ * @return {@link org.apache.calcite.rex.RexNode} representation of arguments
*/
List<RexNode> rexArguments();
@@ -46,8 +47,9 @@ public interface AggAddContext extends AggResultContext {
List<Expression> arguments();
/**
- * Returns {@link net.hydromatic.optiq.rules.java.RexToLixTranslator} suitable to transform the arguments.
- * @return {@link net.hydromatic.optiq.rules.java.RexToLixTranslator} suitable to transform the arguments.
+ * Returns a
+ * {@link org.apache.calcite.adapter.enumerable.RexToLixTranslator}
+ * suitable to transform the arguments.
*/
RexToLixTranslator rowTranslator();
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggContext.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggContext.java
index 5582c50..a72471a 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggContext.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggContext.java
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import org.eigenbase.rel.Aggregation;
-import org.eigenbase.reltype.RelDataType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlAggFunction;
import java.lang.reflect.Type;
import java.util.List;
@@ -32,12 +32,15 @@ public interface AggContext {
* Returns the aggregation being implemented.
* @return aggregation being implemented.
*/
- Aggregation aggregation();
+ SqlAggFunction aggregation();
/**
- * Returns the return type of the aggregate as {@link org.eigenbase.reltype.RelDataType}.
- * This can be helpful to test {@link org.eigenbase.reltype.RelDataType#isNullable()}.
- * @return return type of the aggregate as {@link org.eigenbase.reltype.RelDataType}
+ * Returns the return type of the aggregate as
+ * {@link org.apache.calcite.rel.type.RelDataType}.
+ * This can be helpful to test
+ * {@link org.apache.calcite.rel.type.RelDataType#isNullable()}.
+ *
+ * @return return type of the aggregate
*/
RelDataType returnRelType();
@@ -48,15 +51,18 @@ public interface AggContext {
Type returnType();
/**
- * Returns the parameter types of the aggregate as {@link org.eigenbase.reltype.RelDataType}.
- * This can be helpful to test {@link org.eigenbase.reltype.RelDataType#isNullable()}.
- * @return parameter types of the aggregate as {@link org.eigenbase.reltype.RelDataType}
+ * Returns the parameter types of the aggregate as
+ * {@link org.apache.calcite.rel.type.RelDataType}.
+ * This can be helpful to test
+ * {@link org.apache.calcite.rel.type.RelDataType#isNullable()}.
*/
List<? extends RelDataType> parameterRelTypes();
/**
- * Returns the parameter types of the aggregate as {@link java.lang.reflect.Type}.
- * @return parameter types of the aggregate as {@link java.lang.reflect.Type}
+ * Returns the parameter types of the aggregate as
+ * {@link java.lang.reflect.Type}.
*/
List<? extends Type> parameterTypes();
}
+
+// End AggContext.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImpState.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImpState.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImpState.java
index 5301993..1c8909a 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImpState.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImpState.java
@@ -14,11 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import net.hydromatic.linq4j.expressions.Expression;
-
-import org.eigenbase.rel.AggregateCall;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.rel.core.AggregateCall;
import java.util.List;
@@ -46,3 +45,5 @@ class AggImpState {
}
}
}
+
+// End AggImpState.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImplementor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImplementor.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImplementor.java
index b4e2f17..6f70828 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImplementor.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggImplementor.java
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import net.hydromatic.linq4j.expressions.Expression;
+import org.apache.calcite.linq4j.tree.Expression;
import java.lang.reflect.Type;
import java.util.List;
@@ -25,17 +25,20 @@ import java.util.List;
* Implements an aggregate function by generating expressions to
* initialize, add to, and get a result from, an accumulator.
*
- * @see net.hydromatic.optiq.rules.java.StrictAggImplementor
- * @see net.hydromatic.optiq.rules.java.StrictWinAggImplementor
- * @see net.hydromatic.optiq.rules.java.RexImpTable.CountImplementor
- * @see net.hydromatic.optiq.rules.java.RexImpTable.SumImplementor
+ * @see org.apache.calcite.adapter.enumerable.StrictAggImplementor
+ * @see org.apache.calcite.adapter.enumerable.StrictWinAggImplementor
+ * @see org.apache.calcite.adapter.enumerable.RexImpTable.CountImplementor
+ * @see org.apache.calcite.adapter.enumerable.RexImpTable.SumImplementor
*/
public interface AggImplementor {
/**
* Returns the types of the intermediate variables used by the aggregate
* implementation.
- * For instance, for "concatenate to string" this can be {@link java.lang.StringBuilder}.
+ *
+ * <p>For instance, for "concatenate to string" this can be
+ * {@link java.lang.StringBuilder}.
* Calcite calls this method before all other {@code implement*} methods.
+ *
* @param info aggregate context
* @return types of the intermediate variables used by the aggregate
* implementation
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResetContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResetContext.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResetContext.java
index 2e474cd..b3efb21 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResetContext.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResetContext.java
@@ -14,14 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import net.hydromatic.linq4j.expressions.Expression;
+import org.apache.calcite.linq4j.tree.Expression;
import java.util.List;
/**
- * Information for a call to {@link AggImplementor#implementReset(AggContext, AggResetContext)}.
+ * Information for a call to
+ * {@link AggImplementor#implementReset(AggContext, AggResetContext)}.
+ *
* {@link AggResetContext} provides access to the accumulator variables
* that should be reset.
*/
@@ -29,9 +31,11 @@ public interface AggResetContext extends NestedBlockBuilder {
/**
* Returns accumulator variables that should be reset.
* There MUST be an assignment even if you just assign the default value.
+ *
* @return accumulator variables that should be reset or empty list when no
* accumulator variables are used by the aggregate implementation.
- * @see AggImplementor#getStateType(net.hydromatic.optiq.rules.java.AggContext)
+ *
+ * @see AggImplementor#getStateType(org.apache.calcite.adapter.enumerable.AggContext)
*/
List<Expression> accumulator();
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResultContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResultContext.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResultContext.java
index 0a0de5a..fe7ee06 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResultContext.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/AggResultContext.java
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
/**
- * Information for a call to {@link AggImplementor#implementResult(AggContext, AggResultContext)}
- * Typically, the aggregation implementation will convert {@link #accumulator()}
- * to the resulting value of the aggregation.
- * The implementation MUST NOT destroy the contents of {@link #accumulator()}.
+ * Information for a call to
+ * {@link AggImplementor#implementResult(AggContext, AggResultContext)}
+ *
+ * <p>Typically, the aggregation implementation will convert
+ * {@link #accumulator()} to the resulting value of the aggregation. The
+ * implementation MUST NOT destroy the contents of {@link #accumulator()}.
*/
public interface AggResultContext extends NestedBlockBuilder, AggResetContext {
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/CallImplementor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/CallImplementor.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/CallImplementor.java
index ecc1b5d..8f8ea68 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/CallImplementor.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/CallImplementor.java
@@ -14,18 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.rules.java;
+package org.apache.calcite.adapter.enumerable;
-import net.hydromatic.linq4j.expressions.Expression;
-
-import org.eigenbase.rex.RexCall;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.rex.RexCall;
/**
* Implements a call via given translator.
- * <p>
- * @see net.hydromatic.optiq.ScalarFunction
- * @see net.hydromatic.optiq.TableFunction
- * @see net.hydromatic.optiq.rules.java.RexImpTable
+ *
+ * @see org.apache.calcite.schema.ScalarFunction
+ * @see org.apache.calcite.schema.TableFunction
+ * @see org.apache.calcite.adapter.enumerable.RexImpTable
*/
public interface CallImplementor {
/** Implements a call. */
@@ -34,3 +33,5 @@ public interface CallImplementor {
RexCall call,
RexImpTable.NullAs nullAs);
}
+
+// End CallImplementor.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
new file mode 100644
index 0000000..e025c5a
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
@@ -0,0 +1,115 @@
+/*
+ * 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.enumerable;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.tree.BlockStatement;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.MethodDeclaration;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexNode;
+
+import com.google.common.collect.ImmutableList;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.AbstractList;
+import java.util.List;
+
+/**
+ * Utilities for generating programs in the Enumerable (functional)
+ * style.
+ */
+public class EnumUtils {
+ private EnumUtils() {}
+
+ static final boolean BRIDGE_METHODS = true;
+
+ static final List<ParameterExpression> NO_PARAMS =
+ ImmutableList.of();
+
+ static final List<Expression> NO_EXPRS =
+ ImmutableList.of();
+
+ public static final String[] LEFT_RIGHT = {"left", "right"};
+
+ static final boolean B = false;
+
+ /** Declares a method that overrides another method. */
+ public static MethodDeclaration overridingMethodDecl(Method method,
+ Iterable<ParameterExpression> parameters,
+ BlockStatement body) {
+ return Expressions.methodDecl(
+ method.getModifiers() & ~Modifier.ABSTRACT,
+ method.getReturnType(),
+ method.getName(),
+ parameters,
+ body);
+ }
+
+ static Type javaClass(
+ JavaTypeFactory typeFactory, RelDataType type) {
+ final Type clazz = typeFactory.getJavaClass(type);
+ return clazz instanceof Class ? clazz : Object[].class;
+ }
+
+ static Class javaRowClass(
+ JavaTypeFactory typeFactory, RelDataType type) {
+ if (type.isStruct() && type.getFieldCount() == 1) {
+ type = type.getFieldList().get(0).getType();
+ }
+ final Type clazz = typeFactory.getJavaClass(type);
+ return clazz instanceof Class ? (Class) clazz : Object[].class;
+ }
+
+ static List<Type> fieldTypes(
+ final JavaTypeFactory typeFactory,
+ final List<? extends RelDataType> inputTypes) {
+ return new AbstractList<Type>() {
+ public Type get(int index) {
+ return EnumUtils.javaClass(typeFactory, inputTypes.get(index));
+ }
+ public int size() {
+ return inputTypes.size();
+ }
+ };
+ }
+
+ static List<RelDataType> fieldRowTypes(
+ final RelDataType inputRowType,
+ final List<? extends RexNode> extraInputs,
+ final List<Integer> argList) {
+ final List<RelDataTypeField> inputFields = inputRowType.getFieldList();
+ return new AbstractList<RelDataType>() {
+ public RelDataType get(int index) {
+ final int arg = argList.get(index);
+ return arg < inputFields.size()
+ ? inputFields.get(arg).getType()
+ : extraInputs.get(arg - inputFields.size()).getType();
+ }
+ public int size() {
+ return argList.size();
+ }
+ };
+ }
+}
+
+// End EnumUtils.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java
new file mode 100644
index 0000000..7f19cdf
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregate.java
@@ -0,0 +1,425 @@
+/*
+ * 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.enumerable;
+
+import org.apache.calcite.adapter.enumerable.impl.AggAddContextImpl;
+import org.apache.calcite.adapter.enumerable.impl.AggResultContextImpl;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.function.Function0;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.function.Function2;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.prepare.CalcitePrepareImpl;
+import org.apache.calcite.rel.InvalidRelException;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
+
+import com.google.common.collect.ImmutableList;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.List;
+
+/** Implementation of {@link org.apache.calcite.rel.core.Aggregate} in
+ * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */
+public class EnumerableAggregate extends Aggregate
+ implements EnumerableRel {
+ private static final List<SqlAggFunction> SUPPORTED_AGGREGATIONS =
+ ImmutableList.of(
+ SqlStdOperatorTable.COUNT,
+ SqlStdOperatorTable.MIN,
+ SqlStdOperatorTable.MAX,
+ SqlStdOperatorTable.SUM);
+
+ public EnumerableAggregate(
+ RelOptCluster cluster,
+ RelTraitSet traitSet,
+ RelNode child,
+ BitSet groupSet,
+ List<AggregateCall> aggCalls)
+ throws InvalidRelException {
+ super(cluster, traitSet, child, groupSet, aggCalls);
+ assert getConvention() instanceof EnumerableConvention;
+
+ for (AggregateCall aggCall : aggCalls) {
+ if (aggCall.isDistinct()) {
+ throw new InvalidRelException(
+ "distinct aggregation not supported");
+ }
+ AggImplementor implementor2 =
+ RexImpTable.INSTANCE.get(aggCall.getAggregation(), false);
+ if (implementor2 == null) {
+ throw new InvalidRelException(
+ "aggregation " + aggCall.getAggregation() + " not supported");
+ }
+ }
+ }
+
+ @Override public EnumerableAggregate copy(RelTraitSet traitSet,
+ RelNode input, BitSet groupSet, List<AggregateCall> aggCalls) {
+ try {
+ return new EnumerableAggregate(getCluster(), traitSet, input,
+ groupSet, aggCalls);
+ } catch (InvalidRelException e) {
+ // Semantic error not possible. Must be a bug. Convert to
+ // internal error.
+ throw new AssertionError(e);
+ }
+ }
+
+ public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
+ final JavaTypeFactory typeFactory = implementor.getTypeFactory();
+ final BlockBuilder builder = new BlockBuilder();
+ final EnumerableRel child = (EnumerableRel) getInput();
+ final Result result = implementor.visitChild(this, 0, child, pref);
+ Expression childExp =
+ builder.append(
+ "child",
+ result.block);
+ final RelDataType inputRowType = getInput().getRowType();
+
+ final PhysType physType =
+ PhysTypeImpl.of(
+ typeFactory, getRowType(), pref.preferCustom());
+
+ // final Enumerable<Employee> child = <<child adapter>>;
+ // Function1<Employee, Integer> keySelector =
+ // new Function1<Employee, Integer>() {
+ // public Integer apply(Employee a0) {
+ // return a0.deptno;
+ // }
+ // };
+ // Function1<Employee, Object[]> accumulatorInitializer =
+ // new Function1<Employee, Object[]>() {
+ // public Object[] apply(Employee a0) {
+ // return new Object[] {0, 0};
+ // }
+ // };
+ // Function2<Object[], Employee, Object[]> accumulatorAdder =
+ // new Function2<Object[], Employee, Object[]>() {
+ // public Object[] apply(Object[] a1, Employee a0) {
+ // a1[0] = ((Integer) a1[0]) + 1;
+ // a1[1] = ((Integer) a1[1]) + a0.salary;
+ // return a1;
+ // }
+ // };
+ // Function2<Integer, Object[], Object[]> resultSelector =
+ // new Function2<Integer, Object[], Object[]>() {
+ // public Object[] apply(Integer a0, Object[] a1) {
+ // return new Object[] { a0, a1[0], a1[1] };
+ // }
+ // };
+ // return childEnumerable
+ // .groupBy(
+ // keySelector, accumulatorInitializer, accumulatorAdder,
+ // resultSelector);
+ //
+ // or, if key has 0 columns,
+ //
+ // return childEnumerable
+ // .aggregate(
+ // accumulatorInitializer.apply(),
+ // accumulatorAdder,
+ // resultSelector);
+ //
+ // with a slightly different resultSelector; or if there are no aggregate
+ // functions
+ //
+ // final Enumerable<Employee> child = <<child adapter>>;
+ // Function1<Employee, Integer> keySelector =
+ // new Function1<Employee, Integer>() {
+ // public Integer apply(Employee a0) {
+ // return a0.deptno;
+ // }
+ // };
+ // EqualityComparer<Employee> equalityComparer =
+ // new EqualityComparer<Employee>() {
+ // boolean equal(Employee a0, Employee a1) {
+ // return a0.deptno;
+ // }
+ // };
+ // return child
+ // .distinct(equalityComparer);
+
+ final PhysType inputPhysType = result.physType;
+
+ ParameterExpression parameter =
+ Expressions.parameter(inputPhysType.getJavaRowType(), "a0");
+
+ final PhysType keyPhysType =
+ inputPhysType.project(
+ BitSets.toList(groupSet), JavaRowFormat.LIST);
+ final int keyArity = groupSet.cardinality();
+ final Expression keySelector =
+ builder.append(
+ "keySelector",
+ inputPhysType.generateSelector(
+ parameter,
+ BitSets.toList(groupSet),
+ keyPhysType.getFormat()));
+
+ final List<AggImpState> aggs =
+ new ArrayList<AggImpState>(aggCalls.size());
+
+ for (int i = 0; i < aggCalls.size(); i++) {
+ AggregateCall call = aggCalls.get(i);
+ aggs.add(new AggImpState(i, call, false));
+ }
+
+ // Function0<Object[]> accumulatorInitializer =
+ // new Function0<Object[]>() {
+ // public Object[] apply() {
+ // return new Object[] {0, 0};
+ // }
+ // };
+ final List<Expression> initExpressions =
+ new ArrayList<Expression>();
+ final BlockBuilder initBlock = new BlockBuilder();
+
+ final List<Type> aggStateTypes = new ArrayList<Type>();
+ for (final AggImpState agg : aggs) {
+ agg.context =
+ new AggContext() {
+ public org.apache.calcite.sql.SqlAggFunction aggregation() {
+ return agg.call.getAggregation();
+ }
+
+ public RelDataType returnRelType() {
+ return agg.call.type;
+ }
+
+ public Type returnType() {
+ return EnumUtils.javaClass(typeFactory, returnRelType());
+ }
+
+ public List<? extends RelDataType> parameterRelTypes() {
+ return EnumUtils.fieldRowTypes(inputRowType, null,
+ agg.call.getArgList());
+ }
+
+ public List<? extends Type> parameterTypes() {
+ return EnumUtils.fieldTypes(typeFactory,
+ parameterRelTypes());
+ }
+ };
+ List<Type> state =
+ agg.implementor.getStateType(agg.context);
+
+ if (state.isEmpty()) {
+ continue;
+ }
+
+ aggStateTypes.addAll(state);
+
+ final List<Expression> decls =
+ new ArrayList<Expression>(state.size());
+ for (int i = 0; i < state.size(); i++) {
+ String aggName = "a" + agg.aggIdx;
+ if (CalcitePrepareImpl.DEBUG) {
+ aggName = Util.toJavaId(agg.call.getAggregation().getName(), 0)
+ .substring("ID$0$".length()) + aggName;
+ }
+ Type type = state.get(i);
+ ParameterExpression pe =
+ Expressions.parameter(type,
+ initBlock.newName(aggName + "s" + i));
+ initBlock.add(Expressions.declare(0, pe, null));
+ decls.add(pe);
+ }
+ agg.state = decls;
+ initExpressions.addAll(decls);
+ agg.implementor.implementReset(agg.context,
+ new AggResultContextImpl(initBlock, decls));
+ }
+
+ final PhysType accPhysType =
+ PhysTypeImpl.of(
+ typeFactory,
+ typeFactory.createSyntheticType(aggStateTypes));
+
+ initBlock.add(accPhysType.record(initExpressions));
+
+ final Expression accumulatorInitializer =
+ builder.append(
+ "accumulatorInitializer",
+ Expressions.lambda(
+ Function0.class,
+ initBlock.toBlock()));
+
+ // Function2<Object[], Employee, Object[]> accumulatorAdder =
+ // new Function2<Object[], Employee, Object[]>() {
+ // public Object[] apply(Object[] acc, Employee in) {
+ // acc[0] = ((Integer) acc[0]) + 1;
+ // acc[1] = ((Integer) acc[1]) + in.salary;
+ // return acc;
+ // }
+ // };
+ final BlockBuilder builder2 = new BlockBuilder();
+ final ParameterExpression inParameter =
+ Expressions.parameter(inputPhysType.getJavaRowType(), "in");
+ final ParameterExpression acc_ =
+ Expressions.parameter(accPhysType.getJavaRowType(), "acc");
+ for (int i = 0, stateOffset = 0; i < aggs.size(); i++) {
+ final AggImpState agg = aggs.get(i);
+
+ int stateSize = agg.state.size();
+ List<Expression> accumulator =
+ new ArrayList<Expression>(stateSize);
+ for (int j = 0; j < stateSize; j++) {
+ accumulator.add(accPhysType.fieldReference(
+ acc_, j + stateOffset));
+ }
+ agg.state = accumulator;
+
+ stateOffset += stateSize;
+
+ AggAddContext addContext =
+ new AggAddContextImpl(builder2, accumulator) {
+ public List<RexNode> rexArguments() {
+ List<RelDataTypeField> inputTypes =
+ inputPhysType.getRowType().getFieldList();
+ List<RexNode> args = new ArrayList<RexNode>();
+ for (Integer index : agg.call.getArgList()) {
+ args.add(new RexInputRef(index,
+ inputTypes.get(index).getType()));
+ }
+ return args;
+ }
+
+ public RexToLixTranslator rowTranslator() {
+ return RexToLixTranslator.forAggregation(typeFactory,
+ currentBlock(), new RexToLixTranslator.InputGetterImpl(
+ Collections.singletonList(Pair.of(
+ (Expression) inParameter, inputPhysType))))
+ .setNullable(currentNullables());
+ }
+ };
+
+ agg.implementor.implementAdd(agg.context, addContext);
+ }
+ builder2.add(acc_);
+ final Expression accumulatorAdder =
+ builder.append(
+ "accumulatorAdder",
+ Expressions.lambda(
+ Function2.class,
+ builder2.toBlock(),
+ acc_,
+ inParameter));
+
+ // Function2<Integer, Object[], Object[]> resultSelector =
+ // new Function2<Integer, Object[], Object[]>() {
+ // public Object[] apply(Integer key, Object[] acc) {
+ // return new Object[] { key, acc[0], acc[1] };
+ // }
+ // };
+ final BlockBuilder resultBlock = new BlockBuilder();
+ final List<Expression> results = Expressions.list();
+ final ParameterExpression key_;
+ if (keyArity == 0) {
+ key_ = null;
+ } else {
+ final Type keyType = keyPhysType.getJavaRowType();
+ key_ = Expressions.parameter(keyType, "key");
+ for (int j = 0; j < keyArity; j++) {
+ results.add(
+ keyPhysType.fieldReference(key_, j));
+ }
+ }
+ for (final AggImpState agg : aggs) {
+ results.add(
+ agg.implementor.implementResult(agg.context,
+ new AggResultContextImpl(resultBlock, agg.state)));
+ }
+ resultBlock.add(physType.record(results));
+ if (keyArity == 0) {
+ final Expression resultSelector =
+ builder.append(
+ "resultSelector",
+ Expressions.lambda(
+ Function1.class,
+ resultBlock.toBlock(),
+ acc_));
+ builder.add(
+ Expressions.return_(
+ null,
+ Expressions.call(
+ BuiltInMethod.SINGLETON_ENUMERABLE.method,
+ Expressions.call(
+ childExp,
+ BuiltInMethod.AGGREGATE.method,
+ Expressions.call(accumulatorInitializer, "apply"),
+ accumulatorAdder,
+ resultSelector))));
+ } else if (aggCalls.isEmpty()
+ && groupSet.equals(
+ BitSets.range(child.getRowType().getFieldCount()))) {
+ builder.add(
+ Expressions.return_(
+ null,
+ Expressions.call(
+ inputPhysType.convertTo(childExp, physType),
+ BuiltInMethod.DISTINCT.method,
+ Expressions.<Expression>list()
+ .appendIfNotNull(physType.comparer()))));
+ } else {
+ final Expression resultSelector =
+ builder.append(
+ "resultSelector",
+ Expressions.lambda(
+ Function2.class,
+ resultBlock.toBlock(),
+ key_,
+ acc_));
+ builder.add(
+ Expressions.return_(
+ null,
+ Expressions.call(
+ childExp,
+ BuiltInMethod.GROUP_BY2.method,
+ Expressions
+ .list(
+ keySelector,
+ accumulatorInitializer,
+ accumulatorAdder,
+ resultSelector)
+ .appendIfNotNull(
+ keyPhysType.comparer()))));
+ }
+ return implementor.result(physType, builder.toBlock());
+ }
+}
+
+// End EnumerableAggregate.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregateRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregateRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregateRule.java
new file mode 100644
index 0000000..c04cd03
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregateRule.java
@@ -0,0 +1,54 @@
+/*
+ * 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.enumerable;
+
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.InvalidRelException;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.convert.ConverterRule;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+
+/**
+ * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalAggregate}
+ * to an {@link EnumerableAggregate}.
+ */
+class EnumerableAggregateRule extends ConverterRule {
+ EnumerableAggregateRule() {
+ super(LogicalAggregate.class, Convention.NONE,
+ EnumerableConvention.INSTANCE, "EnumerableAggregateRule");
+ }
+
+ public RelNode convert(RelNode rel) {
+ final LogicalAggregate agg = (LogicalAggregate) rel;
+ final RelTraitSet traitSet =
+ agg.getTraitSet().replace(EnumerableConvention.INSTANCE);
+ try {
+ return new EnumerableAggregate(
+ rel.getCluster(),
+ traitSet,
+ convert(agg.getInput(), traitSet),
+ agg.getGroupSet(),
+ agg.getAggCallList());
+ } catch (InvalidRelException e) {
+ EnumerableRules.LOGGER.fine(e.toString());
+ return null;
+ }
+ }
+}
+
+// End EnumerableAggregateRule.java