You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2014/04/24 09:08:19 UTC
[01/10] git commit: DRILL-327: - Use sqlline 1.1.6,
and change the license file accordingly. Original patch by B Anil
Kumar.
Repository: incubator-drill
Updated Branches:
refs/heads/master 059caed97 -> 9906e06e0
DRILL-327: - Use sqlline 1.1.6, and change the license file accordingly. Original patch by B Anil Kumar.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/f836d5e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/f836d5e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/f836d5e8
Branch: refs/heads/master
Commit: f836d5e80f071ff859202379368fd6a1c989bb22
Parents: 059caed
Author: Patrick Wong <pw...@maprtech.com>
Authored: Wed Apr 23 12:52:05 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Wed Apr 23 14:34:01 2014 -0700
----------------------------------------------------------------------
LICENSE | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/f836d5e8/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 124026f..98d9950 100644
--- a/LICENSE
+++ b/LICENSE
@@ -542,7 +542,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For
- sqlline (http://github.com/julianhyde/sqlline) sqlline:sqlline:jar:1.1.0
+ sqlline (http://github.com/julianhyde/sqlline) sqlline:sqlline:jar:1.1.6
Copyright (c) 2002,2003,2004,2005,2006,2007 Marc Prud'hommeaux
Copyright (c) 2004-2010 The Eigenbase Project
[02/10] Make tests extend shared base class. Add additional tracking
in base class around memory usage per test.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcDistQuery.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcDistQuery.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcDistQuery.java
index caa388a..f371f45 100644
--- a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcDistQuery.java
+++ b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcDistQuery.java
@@ -28,18 +28,18 @@ import java.util.concurrent.TimeUnit;
import org.apache.drill.common.util.TestTools;
import org.apache.drill.exec.store.hive.HiveTestDataGenerator;
import org.apache.drill.jdbc.Driver;
+import org.apache.drill.jdbc.JdbcTest;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import com.google.common.base.Stopwatch;
-public class TestJdbcDistQuery {
+public class TestJdbcDistQuery extends JdbcTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestJdbcDistQuery.class);
-
+
// Set a timeout unless we're debugging.
@Rule public TestRule TIMEOUT = TestTools.getTimeoutRule(50000);
@@ -47,78 +47,78 @@ public class TestJdbcDistQuery {
static{
Driver.load();
WORKING_PATH = Paths.get("").toAbsolutePath().toString();
-
+
}
-
+
@BeforeClass
public static void generateHive() throws Exception{
new HiveTestDataGenerator().generateTestData();
}
-
- @Test
+
+ @Test
public void testSimpleQuerySingleFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, R_NAME "
- + "from dfs.`%s/../sample-data/regionsSF/`", WORKING_PATH));
+ + "from dfs.`%s/../sample-data/regionsSF/`", WORKING_PATH));
}
-
- @Test
+
+ @Test
public void testSimpleQueryMultiFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, R_NAME "
- + "from dfs.`%s/../sample-data/regionsMF/`", WORKING_PATH));
+ + "from dfs.`%s/../sample-data/regionsMF/`", WORKING_PATH));
}
- @Test
+ @Test
public void testWhereOverSFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, R_NAME "
+ "from dfs.`%s/../sample-data/regionsSF/` "
- + "WHERE R_REGIONKEY = 1", WORKING_PATH));
+ + "WHERE R_REGIONKEY = 1", WORKING_PATH));
}
- @Test
+ @Test
public void testWhereOverMFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, R_NAME "
+ "from dfs.`%s/../sample-data/regionsMF/` "
- + "WHERE R_REGIONKEY = 1", WORKING_PATH));
+ + "WHERE R_REGIONKEY = 1", WORKING_PATH));
}
-
- @Test
+
+ @Test
public void testAggSingleFile() throws Exception{
testQuery(String.format("select R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsSF/` "
- + "group by R_REGIONKEY", WORKING_PATH));
+ + "group by R_REGIONKEY", WORKING_PATH));
}
-
+
@Test
public void testAggMultiFile() throws Exception{
testQuery(String.format("select R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsMF/` "
- + "group by R_REGIONKEY", WORKING_PATH));
+ + "group by R_REGIONKEY", WORKING_PATH));
}
-
+
@Test
- public void testAggOrderByDiffGKeyMultiFile() throws Exception{
+ public void testAggOrderByDiffGKeyMultiFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, SUM(cast(R_REGIONKEY AS int)) As S "
+ "from dfs.`%s/../sample-data/regionsMF/` "
- + "group by R_REGIONKEY ORDER BY S", WORKING_PATH));
+ + "group by R_REGIONKEY ORDER BY S", WORKING_PATH));
}
-
+
@Test
public void testAggOrderBySameGKeyMultiFile() throws Exception{
testQuery(String.format("select R_REGIONKEY, SUM(cast(R_REGIONKEY AS int)) As S "
+ "from dfs.`%s/../sample-data/regionsMF/` "
+ "group by R_REGIONKEY "
- + "ORDER BY R_REGIONKEY", WORKING_PATH));
+ + "ORDER BY R_REGIONKEY", WORKING_PATH));
}
-
+
@Test
public void testJoinSingleFile() throws Exception{
testQuery(String.format("select T1.R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsSF/` as T1 "
+ "join dfs.`%s/../sample-data/nationsSF/` as T2 "
- + "on T1.R_REGIONKEY = T2.N_REGIONKEY", WORKING_PATH, WORKING_PATH));
+ + "on T1.R_REGIONKEY = T2.N_REGIONKEY", WORKING_PATH, WORKING_PATH));
}
@Test
@@ -126,7 +126,7 @@ public class TestJdbcDistQuery {
testQuery(String.format("select T1.R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsMF/` as T1 "
+ "join dfs.`%s/../sample-data/nationsMF/` as T2 "
- + "on T1.R_REGIONKEY = T2.N_REGIONKEY", WORKING_PATH, WORKING_PATH));
+ + "on T1.R_REGIONKEY = T2.N_REGIONKEY", WORKING_PATH, WORKING_PATH));
}
@Test
@@ -135,7 +135,7 @@ public class TestJdbcDistQuery {
+ "from dfs.`%s/../sample-data/regionsMF/` as T1 "
+ "join dfs.`%s/../sample-data/nationsMF/` as T2 "
+ "on T1.R_REGIONKEY = T2.N_REGIONKEY "
- + "WHERE T1.R_REGIONKEY = 3 ", WORKING_PATH, WORKING_PATH));
+ + "WHERE T1.R_REGIONKEY = 3 ", WORKING_PATH, WORKING_PATH));
}
@Test
@@ -143,7 +143,7 @@ public class TestJdbcDistQuery {
public void testSortSingleFile() throws Exception{
testQuery(String.format("select R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsSF/` "
- + "order by R_REGIONKEY", WORKING_PATH));
+ + "order by R_REGIONKEY", WORKING_PATH));
}
@Test
@@ -151,7 +151,7 @@ public class TestJdbcDistQuery {
public void testSortMultiFile() throws Exception{
testQuery(String.format("select R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsMF/` "
- + "order by R_REGIONKEY", WORKING_PATH));
+ + "order by R_REGIONKEY", WORKING_PATH));
}
@Test
@@ -159,9 +159,9 @@ public class TestJdbcDistQuery {
testQuery(String.format("select R_REGIONKEY "
+ "from dfs.`%s/../sample-data/regionsMF/` "
+ "WHERE R_REGIONKEY = 1 "
- + "order by R_REGIONKEY ", WORKING_PATH ));
+ + "order by R_REGIONKEY ", WORKING_PATH ));
}
-
+
@Test
public void testJoinAggSortWhere() throws Exception{
testQuery(String.format("select T1.R_REGIONKEY, COUNT(1) as CNT "
@@ -170,16 +170,16 @@ public class TestJdbcDistQuery {
+ "on T1.R_REGIONKEY = T2.N_REGIONKEY "
+ "WHERE T1.R_REGIONKEY = 3 "
+ "GROUP BY T1.R_REGIONKEY "
- + "ORDER BY T1.R_REGIONKEY",WORKING_PATH, WORKING_PATH ));
+ + "ORDER BY T1.R_REGIONKEY",WORKING_PATH, WORKING_PATH ));
}
-
+
@Test
public void testSelectLimit() throws Exception{
testQuery(String.format("select R_REGIONKEY, R_NAME "
+ "from dfs.`%s/../sample-data/regionsMF/` "
- + "limit 2", WORKING_PATH));
+ + "limit 2", WORKING_PATH));
}
-
+
private void testQuery(String sql) throws Exception{
boolean success = false;
try (Connection c = DriverManager.getConnection("jdbc:drill:zk=local", null);) {
@@ -214,7 +214,7 @@ public class TestJdbcDistQuery {
}finally{
if(!success) Thread.sleep(2000);
}
-
-
+
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index ef1674f..148c115 100644
--- a/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/sqlparser/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -25,11 +25,10 @@ import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.concurrent.TimeUnit;
-import com.google.common.base.Function;
-import org.apache.drill.common.util.FileUtils;
import org.apache.drill.common.util.TestTools;
import org.apache.drill.exec.store.hive.HiveTestDataGenerator;
import org.apache.drill.jdbc.Driver;
+import org.apache.drill.jdbc.JdbcTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -37,9 +36,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
+import com.google.common.base.Function;
import com.google.common.base.Stopwatch;
-public class TestJdbcQuery {
+public class TestJdbcQuery extends JdbcTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestJdbcQuery.class);
[08/10] git commit: DRILL-452: Conversion functions for external data
types
Posted by ja...@apache.org.
DRILL-452: Conversion functions for external data types
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/3a1e6c9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/3a1e6c9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/3a1e6c9f
Branch: refs/heads/master
Commit: 3a1e6c9fa9df30e14945ff78afd8049e6185bba3
Parents: 166079b
Author: Aditya Kishore <ad...@maprtech.com>
Authored: Tue Mar 25 01:21:50 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu Apr 24 00:07:32 2014 -0700
----------------------------------------------------------------------
.../drill/common/expression/parser/ExprLexer.g | 1 +
.../drill/common/expression/parser/ExprParser.g | 8 +-
.../common/expression/ConvertExpression.java | 82 +++
.../expression/ExpressionStringBuilder.java | 11 +-
.../common/expression/FunctionCallFactory.java | 4 +
.../visitors/AbstractExprVisitor.java | 6 +
.../expression/visitors/AggregateChecker.java | 9 +
.../expression/visitors/ConstantChecker.java | 5 +
.../common/expression/visitors/ExprVisitor.java | 3 +-
.../visitors/ExpressionValidator.java | 9 +-
.../org/apache/drill/common/types/Types.java | 54 +-
.../sig/ConstantExpressionIdentifier.java | 8 +-
.../drill/exec/expr/EvaluationVisitor.java | 12 +
.../exec/expr/ExpressionTreeMaterializer.java | 12 +
.../expr/fn/impl/conv/BigIntBEConvertFrom.java | 46 ++
.../expr/fn/impl/conv/BigIntBEConvertTo.java | 53 ++
.../expr/fn/impl/conv/BigIntConvertFrom.java | 47 ++
.../exec/expr/fn/impl/conv/BigIntConvertTo.java | 54 ++
.../fn/impl/conv/BigIntVLongConvertFrom.java | 43 ++
.../expr/fn/impl/conv/BigIntVLongConvertTo.java | 55 ++
.../fn/impl/conv/BooleanByteConvertFrom.java | 47 ++
.../expr/fn/impl/conv/BooleanByteConvertTo.java | 54 ++
.../fn/impl/conv/DateEpochBEConvertFrom.java | 48 ++
.../expr/fn/impl/conv/DateEpochBEConvertTo.java | 53 ++
.../expr/fn/impl/conv/DateEpochConvertFrom.java | 49 ++
.../expr/fn/impl/conv/DateEpochConvertTo.java | 54 ++
.../expr/fn/impl/conv/DoubleConvertFrom.java | 47 ++
.../exec/expr/fn/impl/conv/DoubleConvertTo.java | 54 ++
.../expr/fn/impl/conv/FloatConvertFrom.java | 47 ++
.../exec/expr/fn/impl/conv/FloatConvertTo.java | 54 ++
.../expr/fn/impl/conv/IntBEConvertFrom.java | 46 ++
.../exec/expr/fn/impl/conv/IntBEConvertTo.java | 53 ++
.../exec/expr/fn/impl/conv/IntConvertFrom.java | 47 ++
.../exec/expr/fn/impl/conv/IntConvertTo.java | 54 ++
.../expr/fn/impl/conv/IntVIntConvertFrom.java | 43 ++
.../expr/fn/impl/conv/IntVIntConvertTo.java | 55 ++
.../fn/impl/conv/SmallIntBEConvertFrom.java | 47 ++
.../expr/fn/impl/conv/SmallIntBEConvertTo.java | 54 ++
.../expr/fn/impl/conv/SmallIntConvertFrom.java | 47 ++
.../expr/fn/impl/conv/SmallIntConvertTo.java | 54 ++
.../fn/impl/conv/TimeEpochBEConvertFrom.java | 47 ++
.../expr/fn/impl/conv/TimeEpochBEConvertTo.java | 53 ++
.../expr/fn/impl/conv/TimeEpochConvertFrom.java | 48 ++
.../expr/fn/impl/conv/TimeEpochConvertTo.java | 54 ++
.../expr/fn/impl/conv/TinyIntConvertFrom.java | 48 ++
.../expr/fn/impl/conv/TinyIntConvertTo.java | 55 ++
.../expr/fn/impl/conv/UInt8ConvertFrom.java | 47 ++
.../exec/expr/fn/impl/conv/UInt8ConvertTo.java | 54 ++
.../expr/fn/impl/conv/UTF16ConvertFrom.java | 52 ++
.../exec/expr/fn/impl/conv/UTF16ConvertTo.java | 52 ++
.../exec/expr/fn/impl/conv/UTF8ConvertFrom.java | 52 ++
.../exec/expr/fn/impl/conv/UTF8ConvertTo.java | 52 ++
.../drill/exec/resolver/TypeCastRules.java | 112 +++++
.../drill/exec/store/hive/HiveRecordReader.java | 31 +-
.../org/apache/drill/exec/util/ConvertUtil.java | 209 ++++++++
.../physical/impl/TestConvertFunctions.java | 498 +++++++++++++++++++
.../conv/conversionTestWithLogicalPlan.json | 61 +++
.../conv/conversionTestWithPhysicalPlan.json | 36 ++
58 files changed, 3052 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprLexer.g
----------------------------------------------------------------------
diff --git a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprLexer.g b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprLexer.g
index b0d082d..58ed215 100644
--- a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprLexer.g
+++ b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprLexer.g
@@ -36,6 +36,7 @@ Case : 'case';
When : 'when';
Cast: 'cast';
+Convert : 'convert_' ('from' | 'to');
Nullable: 'nullable';
Repeat: 'repeat';
As: 'as';
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
----------------------------------------------------------------------
diff --git a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
index ca37e4c..5ad7099 100644
--- a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
+++ b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
@@ -73,7 +73,12 @@ parse returns [LogicalExpression e]
functionCall returns [LogicalExpression e]
: Identifier OParen exprList? CParen {$e = FunctionCallFactory.createExpression($Identifier.text, pos($Identifier), $exprList.listE); }
;
-
+
+convertCall returns [LogicalExpression e]
+ : Convert OParen expression Comma String CParen
+ { $e = FunctionCallFactory.createConvert($Convert.text, $String.text, $expression.e, pos($Convert));}
+ ;
+
castCall returns [LogicalExpression e]
@init{
List<LogicalExpression> exprs = new ArrayList<LogicalExpression>();
@@ -299,6 +304,7 @@ arraySegment returns [PathSegment seg]
lookup returns [LogicalExpression e]
: functionCall {$e = $functionCall.e ;}
+ | convertCall {$e = $convertCall.e; }
| castCall {$e = $castCall.e; }
| pathSegment {$e = new SchemaPath($pathSegment.seg, pos($pathSegment.start) ); }
| String {$e = new ValueExpressions.QuotedString($String.text, pos($String) ); }
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/ConvertExpression.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ConvertExpression.java b/common/src/main/java/org/apache/drill/common/expression/ConvertExpression.java
new file mode 100644
index 0000000..c028083
--- /dev/null
+++ b/common/src/main/java/org/apache/drill/common/expression/ConvertExpression.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.common.expression;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.apache.drill.common.expression.visitors.ExprVisitor;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.Types;
+
+public class ConvertExpression extends LogicalExpressionBase implements Iterable<LogicalExpression>{
+
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ConvertExpression.class);
+
+ private final LogicalExpression input;
+ private final MajorType type;
+ private final String convertFunction;
+ private final String conversionType;
+
+ /**
+ * @param conversionType
+ * @param convertFunction
+ * @param input
+ * @param pos
+ */
+ public ConvertExpression(String convertFunction, String conversionType, LogicalExpression input, ExpressionPosition pos) {
+ super(pos);
+ this.input = input;
+ this.convertFunction = convertFunction.toLowerCase();
+ this.conversionType = conversionType.toUpperCase();
+ this.type = Types.getMajorTypeFromName(conversionType.split("_", 2)[0].toLowerCase());
+ }
+
+ @Override
+ public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+ return visitor.visitConvertExpression(this, value);
+ }
+
+ @Override
+ public Iterator<LogicalExpression> iterator() {
+ return Collections.singleton(input).iterator();
+ }
+
+ public String getConvertFunction() {
+ return convertFunction;
+ }
+
+ public LogicalExpression getInput() {
+ return input;
+ }
+
+ @Override
+ public MajorType getMajorType() {
+ return type;
+ }
+
+ public String getConversionType() {
+ return conversionType;
+ }
+
+ @Override
+ public String toString() {
+ return "ConvertExpression [input=" + input + ", type=" + type + ", convertFunction="
+ + convertFunction + ", conversionType=" + conversionType + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java b/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
index 8b43846..2ec4fca 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
@@ -238,6 +238,14 @@ public class ExpressionStringBuilder extends AbstractExprVisitor<Void, StringBui
}
@Override
+ public Void visitConvertExpression(ConvertExpression e, StringBuilder sb) throws RuntimeException {
+ sb.append(e.getConvertFunction()).append("(");
+ e.getInput().accept(this, sb);
+ sb.append(", \"").append(e.getConversionType()).append("\")");
+ return null;
+ }
+
+ @Override
public Void visitCastExpression(CastExpression e, StringBuilder sb) throws RuntimeException {
MajorType mt = e.getMajorType();
@@ -310,7 +318,4 @@ public class ExpressionStringBuilder extends AbstractExprVisitor<Void, StringBui
return null;
}
-
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java b/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
index 8113107..6e8e0f4 100644
--- a/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
+++ b/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
@@ -79,6 +79,10 @@ public class FunctionCallFactory {
return new CastExpression(expr, type, ep);
}
+ public static LogicalExpression createConvert(String function, String conversionType, LogicalExpression expr, ExpressionPosition ep) {
+ return new ConvertExpression(function, conversionType, expr, ep);
+ }
+
public static LogicalExpression createExpression(String functionName, List<LogicalExpression> args){
return createExpression(functionName, ExpressionPosition.UNKNOWN, args);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java b/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
index 7ed36f6..526275f 100644
--- a/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
+++ b/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
@@ -18,6 +18,7 @@
package org.apache.drill.common.expression.visitors;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
import org.apache.drill.common.expression.IfExpression;
@@ -144,6 +145,11 @@ public abstract class AbstractExprVisitor<T, VAL, EXCEP extends Exception> imple
}
@Override
+ public T visitConvertExpression(ConvertExpression e, VAL value) throws EXCEP {
+ return visitUnknown(e, value);
+ }
+
+ @Override
public T visitUnknown(LogicalExpression e, VAL value) throws EXCEP {
throw new UnsupportedOperationException(String.format("Expression of type %s not handled by visitor type %s.", e.getClass().getCanonicalName(), this.getClass().getCanonicalName()));
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java b/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
index 4291dee..bf67a6b 100644
--- a/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
+++ b/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
@@ -18,6 +18,7 @@
package org.apache.drill.common.expression.visitors;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.ErrorCollector;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
@@ -147,9 +148,15 @@ public final class AggregateChecker implements ExprVisitor<Boolean, ErrorCollect
}
@Override
+ public Boolean visitConvertExpression(ConvertExpression e, ErrorCollector errors) throws RuntimeException {
+ return e.getInput().accept(this, errors);
+ }
+
+ @Override
public Boolean visitDateConstant(DateExpression intExpr, ErrorCollector errors) {
return false;
}
+
@Override
public Boolean visitTimeConstant(TimeExpression intExpr, ErrorCollector errors) {
return false;
@@ -164,8 +171,10 @@ public final class AggregateChecker implements ExprVisitor<Boolean, ErrorCollect
public Boolean visitIntervalYearConstant(IntervalYearExpression intExpr, ErrorCollector errors) {
return false;
}
+
@Override
public Boolean visitIntervalDayConstant(IntervalDayExpression intExpr, ErrorCollector errors) {
return false;
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java b/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
index 09fbedf..ab94987 100644
--- a/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
+++ b/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
@@ -18,6 +18,7 @@
package org.apache.drill.common.expression.visitors;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.ErrorCollector;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
@@ -175,4 +176,8 @@ final class ConstantChecker implements ExprVisitor<Boolean, ErrorCollector, Runt
return e.getInput().accept(this, value);
}
+ @Override
+ public Boolean visitConvertExpression(ConvertExpression e, ErrorCollector value) throws RuntimeException {
+ return e.getInput().accept(this, value);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java b/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
index 92fd777..799c9dd 100644
--- a/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
+++ b/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
@@ -18,6 +18,7 @@
package org.apache.drill.common.expression.visitors;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
import org.apache.drill.common.expression.IfExpression;
@@ -62,5 +63,5 @@ public interface ExprVisitor<T, VAL, EXCEP extends Exception> {
public T visitQuotedStringConstant(QuotedString e, VAL value) throws EXCEP;
public T visitUnknown(LogicalExpression e, VAL value) throws EXCEP;
public T visitCastExpression(CastExpression e, VAL value) throws EXCEP;
-
+ public T visitConvertExpression(ConvertExpression e, VAL value) throws EXCEP;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/expression/visitors/ExpressionValidator.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/visitors/ExpressionValidator.java b/common/src/main/java/org/apache/drill/common/expression/visitors/ExpressionValidator.java
index 1caf145..e9bd03a 100644
--- a/common/src/main/java/org/apache/drill/common/expression/visitors/ExpressionValidator.java
+++ b/common/src/main/java/org/apache/drill/common/expression/visitors/ExpressionValidator.java
@@ -18,6 +18,7 @@
package org.apache.drill.common.expression.visitors;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.ErrorCollector;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
@@ -194,7 +195,13 @@ public class ExpressionValidator implements ExprVisitor<Void, ErrorCollector, Ru
@Override
public Void visitCastExpression(CastExpression e, ErrorCollector value) throws RuntimeException {
- return e.accept(this, value);
+ return e.getInput().accept(this, value);
+ }
+
+ @Override
+ public Void visitConvertExpression(ConvertExpression e, ErrorCollector value)
+ throws RuntimeException {
+ return e.getInput().accept(this, value);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/common/src/main/java/org/apache/drill/common/types/Types.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/types/Types.java b/common/src/main/java/org/apache/drill/common/types/Types.java
index 5418e50..c51177d 100644
--- a/common/src/main/java/org/apache/drill/common/types/Types.java
+++ b/common/src/main/java/org/apache/drill/common/types/Types.java
@@ -255,6 +255,10 @@ public class Types {
return type.getMinorType() == MinorType.LATE;
}
+ public static MajorType withMode(MinorType type, DataMode mode){
+ return MajorType.newBuilder().setMode(mode).setMinorType(type).build();
+ }
+
public static MajorType required(MinorType type){
return MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(type).build();
}
@@ -279,6 +283,54 @@ public class Types {
throw new UnsupportedOperationException();
}
}
+
+ public static MajorType getMajorTypeFromName(String typeName) {
+ return getMajorTypeFromName(typeName, DataMode.REQUIRED);
+ }
-
+ public static MajorType getMajorTypeFromName(String typeName, DataMode mode) {
+ switch (typeName) {
+ case "bool":
+ case "boolean":
+ return withMode(MinorType.BIT, mode);
+ case "tinyint":
+ return withMode(MinorType.TINYINT, mode);
+ case "uint1":
+ return withMode(MinorType.UINT1, mode);
+ case "smallint":
+ return withMode(MinorType.SMALLINT, mode);
+ case "uint2":
+ return withMode(MinorType.UINT2, mode);
+ case "int":
+ return withMode(MinorType.INT, mode);
+ case "uint4":
+ return withMode(MinorType.UINT4, mode);
+ case "bigint":
+ return withMode(MinorType.BIGINT, mode);
+ case "uint8":
+ return withMode(MinorType.UINT8, mode);
+ case "float":
+ return withMode(MinorType.FLOAT4, mode);
+ case "double":
+ return withMode(MinorType.FLOAT8, mode);
+ case "decimal":
+ return withMode(MinorType.DECIMAL38SPARSE, mode);
+ case "utf8":
+ case "varchar":
+ return withMode(MinorType.VARCHAR, mode);
+ case "utf16":
+ case "string":
+ case "var16char":
+ return withMode(MinorType.VAR16CHAR, mode);
+ case "date":
+ return withMode(MinorType.DATE, mode);
+ case "time":
+ return withMode(MinorType.TIME, mode);
+ case "binary":
+ return withMode(MinorType.VARBINARY, mode);
+ default:
+ throw new UnsupportedOperationException("Could not determine type: " + typeName);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/compile/sig/ConstantExpressionIdentifier.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/sig/ConstantExpressionIdentifier.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/sig/ConstantExpressionIdentifier.java
index 2b125cd..5cff001 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/sig/ConstantExpressionIdentifier.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/sig/ConstantExpressionIdentifier.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Set;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
import org.apache.drill.common.expression.IfExpression;
@@ -202,5 +203,10 @@ public class ConstantExpressionIdentifier implements ExprVisitor<Boolean, Identi
public Boolean visitUnknown(LogicalExpression e, IdentityHashMap<LogicalExpression, Object> value){
return checkChildren(e, value, false);
}
-
+
+ @Override
+ public Boolean visitConvertExpression(ConvertExpression e,
+ IdentityHashMap<LogicalExpression, Object> value) throws RuntimeException {
+ return e.getInput().accept(this, value);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
index fd547e1..dce070f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
@@ -23,6 +23,7 @@ import java.util.Set;
import io.netty.buffer.ByteBuf;
import com.google.common.collect.Lists;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.FunctionHolderExpression;
import org.apache.drill.common.expression.IfExpression;
@@ -440,7 +441,18 @@ public class EvaluationVisitor {
"It should have been converted to FunctionHolderExpression in materialization");
}
+ @Override
+ public HoldingContainer visitConvertExpression(ConvertExpression e, ClassGenerator<?> value) throws RuntimeException {
+ String convertFunctionName = e.getConvertFunction() + e.getConversionType();
+
+ List<LogicalExpression> newArgs = Lists.newArrayList();
+ newArgs.add(e.getInput()); //input_expr
+
+ FunctionCall fc = new FunctionCall(convertFunctionName, newArgs, e.getPosition());
+ return fc.accept(this, value);
+ }
}
+
private class ConstantFilter extends EvalVisitor {
private Set<LogicalExpression> constantBoundaries;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index e3b1002..a602d82 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -21,6 +21,7 @@ import java.util.List;
import com.google.common.base.Joiner;
import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
import org.apache.drill.common.expression.ErrorCollector;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.FunctionCall;
@@ -340,6 +341,17 @@ public class ExpressionTreeMaterializer {
}
@Override
+ public LogicalExpression visitConvertExpression(ConvertExpression e, FunctionImplementationRegistry value) {
+ String convertFunctionName = e.getConvertFunction() + e.getConversionType();
+
+ List<LogicalExpression> newArgs = Lists.newArrayList();
+ newArgs.add(e.getInput()); //input_expr
+
+ FunctionCall fc = new FunctionCall(convertFunctionName, newArgs, e.getPosition());
+ return fc.accept(this, value);
+ }
+
+ @Override
public LogicalExpression visitCastExpression(CastExpression e, FunctionImplementationRegistry value){
// if the cast is pointless, remove it.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
new file mode 100644
index 0000000..01da0b1
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromBIGINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntBEConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output BigIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ out.value = Long.reverseBytes(in.buffer.readLong());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
new file mode 100644
index 0000000..7122937
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toBIGINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntBEConvertTo implements DrillSimpleFunc {
+
+ @Param BigIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(Long.reverseBytes(in.value));
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
new file mode 100644
index 0000000..093de0f
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromBIGINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output BigIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readLong();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
new file mode 100644
index 0000000..70bb6e7
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toBIGINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntConvertTo implements DrillSimpleFunc {
+
+ @Param BigIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
new file mode 100644
index 0000000..d7bbfcc
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromBIGINT_HADOOPV", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntVLongConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output BigIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.value = org.apache.drill.exec.util.ConvertUtil.HadoopWritables.readVLong(in.buffer, in.start, in.end);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
new file mode 100644
index 0000000..4455781
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toBIGINT_HADOOPV", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BigIntVLongConvertTo implements DrillSimpleFunc {
+
+ @Param BigIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ /* Hadoop Variable length integer (represented in the same way as a long)
+ * occupies between 1-9 bytes.
+ */
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(9);
+ }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = buffer.readableBytes();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
new file mode 100644
index 0000000..f72d507
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromBOOLEAN_BYTE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BooleanByteConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output BitHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readByte()==0 ? 0 : 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
new file mode 100644
index 0000000..959deb0
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toBOOLEAN_BYTE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class BooleanByteConvertTo implements DrillSimpleFunc {
+
+ @Param BitHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(1);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeByte(in.value==0 ? 0 : 1);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
new file mode 100644
index 0000000..75bf8d6
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.DateHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromDATE_EPOCH_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DateEpochBEConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output DateHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ long epochMillis = Long.reverseBytes(in.buffer.readLong());
+ long millsOfDay = epochMillis % (24*3600*1000);
+ out.value = epochMillis - millsOfDay;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
new file mode 100644
index 0000000..98b561c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.DateHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toDATE_EPOCH_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DateEpochBEConvertTo implements DrillSimpleFunc {
+
+ @Param DateHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(Long.reverseBytes(in.value));
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
new file mode 100644
index 0000000..713016c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.DateHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromDATE_EPOCH", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DateEpochConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output DateHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ long epochMillis = in.buffer.readLong();
+ long millsOfDay = epochMillis % (24*3600*1000);
+ out.value = epochMillis - millsOfDay;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
new file mode 100644
index 0000000..f0e604e
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.DateHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toDATE_EPOCH", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DateEpochConvertTo implements DrillSimpleFunc {
+
+ @Param DateHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
new file mode 100644
index 0000000..df0bae7
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.Float8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromDOUBLE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DoubleConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output Float8Holder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readDouble();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
new file mode 100644
index 0000000..1f5c38f
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.Float8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toDOUBLE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DoubleConvertTo implements DrillSimpleFunc {
+
+ @Param Float8Holder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeDouble(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
new file mode 100644
index 0000000..9f42b57
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.Float4Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromFLOAT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class FloatConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output Float4Holder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readFloat();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
new file mode 100644
index 0000000..a1d8c7c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.Float4Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toFLOAT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class FloatConvertTo implements DrillSimpleFunc {
+
+ @Param Float4Holder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeFloat(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 4;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
new file mode 100644
index 0000000..d235c66
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntBEConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output IntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+
+ in.buffer.readerIndex(in.start);
+ out.value = Integer.reverseBytes(in.buffer.readInt());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
new file mode 100644
index 0000000..cd13c31
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntBEConvertTo implements DrillSimpleFunc {
+
+ @Param IntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeInt(Integer.reverseBytes(in.value));
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 4;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
new file mode 100644
index 0000000..4563b8e
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output IntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readInt();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
new file mode 100644
index 0000000..8531608
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntConvertTo implements DrillSimpleFunc {
+
+ @Param IntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeInt(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 4;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
new file mode 100644
index 0000000..acb2666
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromINT_HADOOPV", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntVIntConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output IntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.value = org.apache.drill.exec.util.ConvertUtil.HadoopWritables.readVInt(in.buffer, in.start, in.end);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
new file mode 100644
index 0000000..0691838
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toINT_HADOOPV", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class IntVIntConvertTo implements DrillSimpleFunc {
+
+ @Param IntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ /* Hadoop Variable length integer (represented in the same way as a long)
+ * occupies between 1-9 bytes.
+ */
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(9);
+ }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = buffer.readableBytes();
+ }
+}
[04/10] git commit: Make tests extend shared base class. Add
additional tracking in base class around memory usage per test.
Posted by ja...@apache.org.
Make tests extend shared base class. Add additional tracking in base class around memory usage per test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/16481951
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/16481951
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/16481951
Branch: refs/heads/master
Commit: 164819513a5915a43103017fe699cc073b53284a
Parents: f836d5e
Author: Jacques Nadeau <ja...@apache.org>
Authored: Mon Apr 21 17:19:02 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Wed Apr 23 17:59:01 2014 -0700
----------------------------------------------------------------------
.../org/apache/drill/common/util/TestTools.java | 31 --
.../common/expression/parser/TreeTest.java | 5 +-
.../drill/storage/CheckStorageConfig.java | 7 +-
.../java/org/apache/drill/storage/Simple.java | 33 --
.../java/org/apache/drill/test/DrillTest.java | 134 +++++
contrib/storage-hbase/pom.xml | 7 +
.../java/org/apache/drill/BaseTestQuery.java | 16 +-
.../java/org/apache/drill/PlanningBase.java | 4 +-
.../apache/drill/exec/DrillSystemTestBase.java | 17 +-
.../java/org/apache/drill/exec/ExecTest.java | 25 +
.../drill/exec/cache/TestVectorCache.java | 4 +-
.../drill/exec/cache/TestWriteToDisk.java | 4 +-
.../apache/drill/exec/client/DumpCatTest.java | 11 +-
.../exec/compile/TestClassCompilationTypes.java | 7 +-
.../exec/compile/TestClassTransformation.java | 17 +-
.../org/apache/drill/exec/expr/EscapeTest1.java | 76 +--
.../apache/drill/exec/expr/ExpressionTest.java | 11 +-
.../drill/exec/fn/impl/GeneratorFunctions.java | 3 +-
.../drill/exec/fn/impl/TestMathFunctions.java | 6 +-
.../exec/fn/impl/TestRepeatedFunction.java | 31 +-
.../apache/drill/exec/memory/TestEndianess.java | 7 +-
.../drill/exec/opt/BasicOptimizerTest.java | 10 +-
.../physical/config/TestParsePhysicalPlan.java | 9 +-
.../physical/impl/TestComparisonFunctions.java | 3 +-
.../drill/exec/physical/impl/TestHiveUDFs.java | 3 +-
.../impl/TestImplicitCastFunctions.java | 49 +-
.../exec/physical/impl/TestOptiqPlans.java | 3 +-
.../exec/physical/impl/TestSimpleFunctions.java | 5 +-
.../exec/physical/impl/TestStringFunctions.java | 129 ++---
.../drill/exec/physical/impl/agg/TestAgg.java | 3 +-
.../physical/impl/common/TestHashTable.java | 9 +-
.../physical/impl/filter/TestSimpleFilter.java | 15 +-
.../physical/impl/limit/TestSimpleLimit.java | 7 +-
.../impl/project/TestSimpleProjection.java | 17 +-
.../exec/physical/impl/sort/TestSimpleSort.java | 53 +-
.../physical/impl/svremover/TestSVRemover.java | 15 +-
.../impl/trace/TestTraceMultiRecordBatch.java | 3 +-
.../impl/trace/TestTraceOutputDump.java | 3 +-
.../physical/impl/union/TestSimpleUnion.java | 21 +-
.../apache/drill/exec/pop/PopUnitTestBase.java | 7 +-
.../drill/exec/pop/TestInjectionValue.java | 13 +-
.../record/ExpressionTreeMaterializerTest.java | 8 +-
.../drill/exec/record/vector/TestLoad.java | 4 +-
.../exec/record/vector/TestValueVector.java | 33 +-
.../apache/drill/exec/server/TestBitRpc.java | 3 +-
.../exec/store/TestAffinityCalculator.java | 3 +-
.../drill/exec/store/TestOrphanSchema.java | 6 +-
.../exec/store/ischema/TestOrphanSchema.java | 3 +-
.../exec/store/ischema/TestTableProvider.java | 3 +-
.../exec/store/json/JSONRecordReaderTest.java | 3 +-
.../store/parquet/TestParquetPhysicalPlan.java | 3 +-
.../exec/work/batch/TestSpoolingBuffer.java | 4 +-
sqlparser/pom.xml | 8 +-
.../java/org/apache/drill/jdbc/JdbcTest.java | 24 +
.../apache/drill/jdbc/test/JdbcDataTest.java | 521 +++++++++++++++++++
.../org/apache/drill/jdbc/test/JdbcTest.java | 520 ------------------
.../drill/jdbc/test/TestJdbcDistQuery.java | 78 +--
.../apache/drill/jdbc/test/TestJdbcQuery.java | 6 +-
58 files changed, 1109 insertions(+), 954 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/common/src/main/java/org/apache/drill/common/util/TestTools.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/util/TestTools.java b/common/src/main/java/org/apache/drill/common/util/TestTools.java
index 6e0c241..5be8d40 100644
--- a/common/src/main/java/org/apache/drill/common/util/TestTools.java
+++ b/common/src/main/java/org/apache/drill/common/util/TestTools.java
@@ -21,10 +21,7 @@ import java.nio.file.Paths;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;
-import org.junit.rules.TestWatcher;
import org.junit.rules.Timeout;
-import org.junit.runner.Description;
-import org.slf4j.Logger;
public class TestTools {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTools.class);
@@ -45,33 +42,5 @@ public class TestTools {
return WORKING_PATH;
}
- public static TestLogReporter getTestLogReporter(final Logger logger) {
- return new TestLogReporter(logger);
- }
-
- public static class TestLogReporter extends TestWatcher{
- private int failureCount = 0;
-
- final Logger logger;
-
- public TestLogReporter(Logger logger) {
- super();
- this.logger = logger;
- }
- @Override
- protected void failed(Throwable e, Description description) {
- logger.error("Test Failed: " + description.getDisplayName(), e);
- failureCount++;
- }
-
- @Override
- public void succeeded(Description description) {
- logger.info("Test Succeeded: " + description.getDisplayName());
- }
-
- public void sleepIfFailure() throws InterruptedException{
- if(failureCount > 0) Thread.sleep(2000);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/common/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java b/common/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
index de090df..39aed44 100644
--- a/common/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
+++ b/common/src/test/java/org/apache/drill/common/expression/parser/TreeTest.java
@@ -25,11 +25,10 @@ import org.antlr.runtime.RecognitionException;
import org.apache.drill.common.expression.ExpressionStringBuilder;
import org.apache.drill.common.expression.LogicalExpression;
import org.apache.drill.common.expression.parser.ExprParser.parse_return;
-import org.junit.Assert;
+import org.apache.drill.test.DrillTest;
import org.junit.Test;
-public class TreeTest {
-
+public class TreeTest extends DrillTest {
@Test
public void testIfWithCase() throws Exception{
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/common/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/storage/CheckStorageConfig.java b/common/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
index 1dc6c77..a3a8257 100644
--- a/common/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
+++ b/common/src/test/java/org/apache/drill/storage/CheckStorageConfig.java
@@ -26,13 +26,12 @@ import org.apache.drill.common.logical.LogicalPlan;
import org.apache.drill.common.logical.StoragePluginConfig;
import org.apache.drill.common.util.FileUtils;
import org.apache.drill.common.util.PathScanner;
+import org.apache.drill.test.DrillTest;
import org.junit.Test;
-import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-public class CheckStorageConfig {
+public class CheckStorageConfig extends DrillTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CheckStorageConfig.class);
@Test
@@ -40,7 +39,7 @@ public class CheckStorageConfig {
Collection<?> engines = PathScanner.scanForImplementations(StoragePluginConfig.class, Lists.newArrayList("org"));
assertEquals(engines.size(), 1);
}
-
+
@Test
public void checkPlanParsing() throws Exception{
LogicalPlan plan = LogicalPlan.parse(DrillConfig.create(), FileUtils.getResourceAsString("/storage_engine_plan.json"));
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/common/src/test/java/org/apache/drill/storage/Simple.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/storage/Simple.java b/common/src/test/java/org/apache/drill/storage/Simple.java
deleted file mode 100644
index b58c451..0000000
--- a/common/src/test/java/org/apache/drill/storage/Simple.java
+++ /dev/null
@@ -1,33 +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.drill.storage;
-
-import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.common.logical.LogicalPlan;
-import org.apache.drill.common.util.FileUtils;
-
-public class Simple {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Simple.class);
-
- public static void main(String[] args) throws Exception {
- DrillConfig c = DrillConfig.create();
- LogicalPlan plan = LogicalPlan.parse(c, FileUtils.getResourceAsString("/jdbc_plan.json"));
- System.out.println(plan.toJsonString(c));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/common/src/test/java/org/apache/drill/test/DrillTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/test/DrillTest.java b/common/src/test/java/org/apache/drill/test/DrillTest.java
new file mode 100644
index 0000000..0b098cb
--- /dev/null
+++ b/common/src/test/java/org/apache/drill/test/DrillTest.java
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.test;
+
+import java.lang.management.BufferPoolMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.util.List;
+
+import org.apache.drill.common.util.TestTools;
+import org.junit.AfterClass;
+import org.junit.Rule;
+import org.junit.rules.TestRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import org.slf4j.Logger;
+
+public class DrillTest {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillTest.class);
+
+ static final SystemManager manager = new SystemManager();
+ static final TestLogReporter LOG_OUTCOME = new TestLogReporter(org.slf4j.LoggerFactory.getLogger("org.apache.drill.TestReporter"));
+
+ @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(50000);
+ @Rule public final TestLogReporter logOutcome = LOG_OUTCOME;
+
+ @AfterClass
+ public static void letLogsCatchUp() throws InterruptedException{
+ LOG_OUTCOME.sleepIfFailure();
+ }
+
+ private static class TestLogReporter extends TestWatcher{
+
+
+ private int failureCount = 0;
+
+ final Logger logger;
+ private long startDirect;
+ private long startHeap;
+ private long startNonHeap;
+
+ public TestLogReporter(Logger logger) {
+ this.logger = logger;
+ }
+
+
+ @Override
+ protected void starting(Description description) {
+ startDirect = manager.getMemDirect();
+ startHeap = manager.getMemHeap();
+ startNonHeap = manager.getMemNonHeap();
+ super.starting(description);
+ }
+
+
+ public String getMemString(){
+ return String.format("d: %s, h: %s, nh: %s", //
+ readable(manager.getMemDirect() - startDirect), //
+ readable(manager.getMemHeap() - startHeap), //
+ readable(manager.getMemNonHeap() - startNonHeap) //
+ );
+ }
+ @Override
+ protected void failed(Throwable e, Description description) {
+ logger.error(String.format("Test Failed (%s): %s", getMemString(), description.getDisplayName()), e);
+ failureCount++;
+ }
+
+ @Override
+ public void succeeded(Description description) {
+ logger.info(String.format("Test Succeeded (%s): %s", getMemString(), description.getDisplayName()));
+ }
+
+ public void sleepIfFailure() throws InterruptedException{
+ if(failureCount > 0){
+ Thread.sleep(2000);
+ failureCount = 0;
+ }
+ }
+ }
+
+ public static String readable(long bytes) {
+ int unit = 1024;
+ if (bytes < unit) return bytes + " B";
+ int exp = (int) (Math.log(bytes) / Math.log(unit));
+ String pre = ("KMGTPE").charAt(exp-1) + ("i");
+ return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
+}
+
+ private static class SystemManager{
+
+ final BufferPoolMXBean directBean;
+ final MemoryMXBean memoryBean;
+
+ public SystemManager(){
+ memoryBean = ManagementFactory.getMemoryMXBean();
+ BufferPoolMXBean localBean = null;
+ List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
+ for(BufferPoolMXBean b : pools){
+ if(b.getName().equals("direct")){
+ localBean = b;
+
+ }
+ }
+ directBean = localBean;
+ }
+
+ public long getMemDirect(){
+ return directBean.getMemoryUsed();
+ }
+
+ public long getMemHeap(){
+ return memoryBean.getHeapMemoryUsage().getUsed();
+ }
+
+ public long getMemNonHeap(){
+ return memoryBean.getNonHeapMemoryUsage().getUsed();
+ }
+ }}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/contrib/storage-hbase/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/pom.xml b/contrib/storage-hbase/pom.xml
index f2a9c62..4067f70 100644
--- a/contrib/storage-hbase/pom.xml
+++ b/contrib/storage-hbase/pom.xml
@@ -75,6 +75,13 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.drill</groupId>
+ <artifactId>drill-common</artifactId>
+ <classifier>tests</classifier>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>1.2.1</version>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index 8b85ac2..86a37ca 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -23,7 +23,7 @@ import java.util.List;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.TestTools;
-import org.apache.drill.common.util.TestTools.TestLogReporter;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.client.PrintingResultsListener;
import org.apache.drill.exec.client.QuerySubmitter;
@@ -37,7 +37,6 @@ import org.apache.drill.exec.server.RemoteServiceSet;
import org.apache.drill.exec.util.VectorUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
@@ -45,20 +44,9 @@ import org.junit.runner.Description;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
-public class BaseTestQuery {
+public class BaseTestQuery extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BaseTestQuery.class);
- // make it static so we can use after class
- static final TestLogReporter LOG_OUTCOME = TestTools.getTestLogReporter(logger);
-
- @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(20000);
- @Rule public final TestLogReporter logOutcome = LOG_OUTCOME;
-
- @AfterClass
- public static void letLogsCatchUp() throws InterruptedException{
- LOG_OUTCOME.sleepIfFailure();
- }
-
public final TestRule resetWatcher = new TestWatcher() {
@Override
protected void failed(Throwable e, Description description) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
index 3a492c5..a3a5647 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
@@ -27,6 +27,7 @@ import net.hydromatic.optiq.tools.Frameworks;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.TestTools;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.cache.DistributedCache;
import org.apache.drill.exec.cache.LocalCache;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
@@ -47,11 +48,10 @@ import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources;
-public class PlanningBase {
+public class PlanningBase extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PlanningBase.class);
@Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(30000);
- @Rule public final TestRule LOG_OUTCOME = TestTools.getTestLogReporter(logger);
@Mocked DrillbitContext dbContext;
@Mocked QueryContext context;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSystemTestBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSystemTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSystemTestBase.java
index 78c46f6..bd45a72 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSystemTestBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSystemTestBase.java
@@ -17,7 +17,12 @@
*/
package org.apache.drill.exec;
-import com.google.common.collect.ImmutableList;
+import static com.google.common.base.Throwables.propagate;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.exception.DrillbitStartupException;
import org.apache.drill.exec.server.Drillbit;
@@ -25,17 +30,13 @@ import org.apache.drill.exec.util.MiniZooKeeperCluster;
import org.junit.BeforeClass;
import org.slf4j.Logger;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import static com.google.common.base.Throwables.propagate;
+import com.google.common.collect.ImmutableList;
/**
* Base class for Drill system tests.
* Starts one or more Drillbits, an embedded ZooKeeper cluster and provides a configured client for testing.
*/
-public class DrillSystemTestBase {
+public class DrillSystemTestBase extends ExecTest{
static final Logger logger = org.slf4j.LoggerFactory.getLogger(DrillConfig.class);
@@ -106,7 +107,7 @@ public class DrillSystemTestBase {
public Drillbit getABit(){
return this.servers.iterator().next();
}
-
+
public static DrillConfig getConfig(){
return config;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java
new file mode 100644
index 0000000..7be8cc5
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec;
+
+import org.apache.drill.test.DrillTest;
+
+public class ExecTest extends DrillTest{
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestVectorCache.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestVectorCache.java b/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestVectorCache.java
index 158d4d7..500500f 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestVectorCache.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestVectorCache.java
@@ -18,11 +18,13 @@
package org.apache.drill.exec.cache;
import com.beust.jcommander.internal.Lists;
+
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.record.*;
import org.apache.drill.exec.server.Drillbit;
@@ -33,7 +35,7 @@ import org.junit.Test;
import java.util.List;
-public class TestVectorCache {
+public class TestVectorCache extends ExecTest{
@Test
public void testVectorCache() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestWriteToDisk.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestWriteToDisk.java b/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestWriteToDisk.java
index 52e8425..22325c4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestWriteToDisk.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/cache/TestWriteToDisk.java
@@ -18,11 +18,13 @@
package org.apache.drill.exec.cache;
import com.beust.jcommander.internal.Lists;
+
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.record.*;
import org.apache.drill.exec.server.Drillbit;
@@ -41,7 +43,7 @@ import org.junit.Test;
import java.util.List;
-public class TestWriteToDisk {
+public class TestWriteToDisk extends ExecTest{
@Test
public void test() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java
index 9545845..62b280d 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java
@@ -26,6 +26,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -57,10 +58,10 @@ import com.google.common.io.Files;
* which will produce a dump file. The dump file will be input into DumpCat to test query mode and batch mode.
*/
-public class DumpCatTest {
+public class DumpCatTest extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DumpCatTest.class);
DrillConfig c = DrillConfig.create();
-
+
@Test
public void testDumpCat(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable
{
@@ -108,12 +109,12 @@ public class DumpCatTest {
FileSystem fs = FileSystem.get(conf);
Path path = new Path(filename);
assertTrue("Trace file does not exist", fs.exists(path));
-
+
DumpCat dumpCat = new DumpCat();
-
+
//Test Query mode
FileInputStream input = new FileInputStream(filename);
-
+
dumpCat.doQuery(input);
input.close();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassCompilationTypes.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassCompilationTypes.java b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassCompilationTypes.java
index 593a0dc..c8f348a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassCompilationTypes.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassCompilationTypes.java
@@ -17,11 +17,12 @@
*/
package org.apache.drill.exec.compile;
+import org.apache.drill.exec.ExecTest;
import org.codehaus.janino.ExpressionEvaluator;
import org.junit.Ignore;
import org.junit.Test;
-public class TestClassCompilationTypes {
+public class TestClassCompilationTypes extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestClassCompilationTypes.class);
@Ignore @Test
@@ -39,7 +40,7 @@ public class TestClassCompilationTypes {
}
}
-
+
private int janino() throws Exception{
// Compile the expression once; relatively slow.
org.codehaus.janino.ExpressionEvaluator ee = new org.codehaus.janino.ExpressionEvaluator("c > d ? c : d", // expression
@@ -52,7 +53,7 @@ public class TestClassCompilationTypes {
return (Integer) ee.evaluate(new Object[] { // parameterValues
new Integer(10), new Integer(11), });
}
-
+
private int jdk() throws Exception{
// Compile the expression once; relatively slow.
ExpressionEvaluator ee = new ExpressionEvaluator("c > d ? c : d", // expression
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
index 654e6da..dd2c91e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
@@ -18,6 +18,7 @@
package org.apache.drill.exec.compile;
import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.compile.sig.GeneratorMapping;
import org.apache.drill.exec.compile.sig.MappingSet;
import org.apache.drill.exec.expr.CodeGenerator;
@@ -25,12 +26,12 @@ import org.apache.drill.exec.expr.ClassGenerator;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.junit.Test;
-public class TestClassTransformation {
+public class TestClassTransformation extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestClassTransformation.class);
-
-
+
+
/**
* Do a test of a three level class to ensure that nested code generators works correctly.
* @throws Exception
@@ -38,16 +39,16 @@ public class TestClassTransformation {
@Test
public void testInnerClassCompilation() throws Exception{
final TemplateClassDefinition<ExampleInner> template = new TemplateClassDefinition<>(ExampleInner.class, ExampleTemplateWithInner.class);
-
+
ClassTransformer ct = new ClassTransformer();
QueryClassLoader loader = new QueryClassLoader(true);
CodeGenerator<ExampleInner> cg = CodeGenerator.get(template, new FunctionImplementationRegistry(DrillConfig.create()));
-
+
ClassGenerator<ExampleInner> root = cg.getRoot();
root.setMappingSet(new MappingSet(new GeneratorMapping("doOutside", null, null, null)));
root.getSetupBlock().directStatement("System.out.println(\"outside\");");
-
-
+
+
ClassGenerator<ExampleInner> inner = root.getInnerGenerator("TheInnerClass");
inner.setMappingSet(new MappingSet(new GeneratorMapping("doInside", null, null, null)));
inner.getSetupBlock().directStatement("System.out.println(\"inside\");");
@@ -59,6 +60,6 @@ public class TestClassTransformation {
ExampleInner t = ct.getImplementationClass(loader, cg.getDefinition(), cg.generate(), cg.getMaterializedClassName());
t.doOutside();
t.doInsideOutside();
-
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/expr/EscapeTest1.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/EscapeTest1.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/EscapeTest1.java
index 7e6868a..3f22da4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/EscapeTest1.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/EscapeTest1.java
@@ -20,8 +20,10 @@ package org.apache.drill.exec.expr;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
-public final class EscapeTest1 {
-
+import org.apache.drill.exec.ExecTest;
+
+public final class EscapeTest1 extends ExecTest{
+
public static class Timer{
long n1;
String name;
@@ -29,16 +31,16 @@ public final class EscapeTest1 {
this.n1 = System.nanoTime();
this.name = name;
}
-
+
public void print(long sum){
System.out.println(String.format("Completed %s in %d ms. Output was %d", name, (System.nanoTime() - n1)/1000/1000, sum));
}
}
-
+
public static Timer time(String name){
return new Timer(name);
}
-
+
public static void main(String args[]){
EscapeTest1 et = new EscapeTest1();
Monkey m = new Monkey();
@@ -52,7 +54,7 @@ public final class EscapeTest1 {
time("get return alloc").print(et.getReturnAlloc(m));
}
}
-
+
public long noAlloc(){
long sum = 0;
for(int i =0; i < 1000000000; i++){
@@ -60,16 +62,16 @@ public final class EscapeTest1 {
}
return sum;
}
-
+
public long alloc(){
long sum = 0;
for(int i =0; i < 1000000000; i++){
- Ad ad = new Ad(i+1, i+2);
+ Ad ad = new Ad(i+1, i+2);
sum+= add(ad.x, ad.y);
}
return sum;
}
-
+
public long setAlloc(Monkey m){
long sum = 0;
for(int i =0; i < 490000000; i++){
@@ -77,18 +79,18 @@ public final class EscapeTest1 {
m.set(h);
sum += i;
}
- return sum;
+ return sum;
}
-
+
public long setNoAlloc(Monkey m){
long sum = 0;
for(int i =0; i < 490000000; i++){
m.set(i+1, i+2);
sum += i;
}
- return sum;
+ return sum;
}
-
+
public long getAlloc(Monkey m){
long sum = 0;
for(int i =0; i < 490000000; i++){
@@ -96,9 +98,9 @@ public final class EscapeTest1 {
m.get(i, i+1, r);
sum += r.v1 + r.v2;
}
- return sum;
+ return sum;
}
-
+
public long getNoAlloc(Monkey m){
long sum = 0;
for(int i =0; i < 490000000; i++){
@@ -106,19 +108,19 @@ public final class EscapeTest1 {
int i2 = m.getV2(i+1);
sum += i1 + i2;
}
- return sum;
+ return sum;
}
-
+
public long getReturnAlloc(Monkey m){
long sum = 0;
for(int i =0; i < 490000000; i++){
RR r = m.get(i, i+1);
sum += r.v1 + r.v2;
}
- return sum;
+ return sum;
}
-
-
+
+
public class Ad{
long x;
long y;
@@ -129,7 +131,7 @@ public final class EscapeTest1 {
}
}
-
+
public static final class EH{
int index;
int value;
@@ -139,13 +141,13 @@ public final class EscapeTest1 {
this.value = value;
}
}
-
+
public static final class RR{
int v1;
int v2;
-
+
public RR(){
-
+
}
public RR(int v1, int v2) {
super();
@@ -153,46 +155,46 @@ public final class EscapeTest1 {
this.v2 = v2;
}
}
-
+
public long add(long a, long b){
return a + b;
}
-
-
+
+
public final static class Monkey{
final IntBuffer buf;
-
+
public Monkey(){
ByteBuffer bb = ByteBuffer.allocateDirect(Integer.MAX_VALUE);
buf = bb.asIntBuffer();
}
-
+
public final void set(int index, int value){
buf.put(index, value);
}
-
+
public final void set(EH a){
buf.put(a.index, a.value);
}
-
+
public final int getV1(int index){
return buf.get(index);
}
-
+
public final int getV2(int index){
return buf.get(index);
}
-
+
public final RR get(int index1, int index2){
return new RR(buf.get(index1), buf.get(index2));
}
-
+
public final void get(int index1, int index2, RR rr){
rr.v1 = buf.get(index1);
rr.v2 = buf.get(index2);
}
-
+
}
-
-
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
index 65b4e76..3fff0e4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java
@@ -38,6 +38,7 @@ import org.apache.drill.common.expression.parser.ExprParser;
import org.apache.drill.common.expression.parser.ExprParser.parse_return;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.physical.impl.project.Projector;
import org.apache.drill.exec.record.RecordBatch;
@@ -48,9 +49,9 @@ import org.apache.drill.exec.vector.ValueVector;
import org.junit.AfterClass;
import org.junit.Test;
-public class ExpressionTest {
+public class ExpressionTest extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTest.class);
-
+
DrillConfig c = DrillConfig.create();
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
@@ -62,7 +63,7 @@ public class ExpressionTest {
@Test
public void testSpecial(final @Injectable RecordBatch batch, @Injectable ValueVector vector) throws Exception {
final TypedFieldId tfid = new TypedFieldId(Types.optional(MinorType.INT),0, false);
-
+
new NonStrictExpectations() {
@NonStrict VectorWrapper<?> wrapper;
{
@@ -70,8 +71,8 @@ public class ExpressionTest {
result = tfid;
batch.getValueAccessorById(tfid.getFieldId(), IntVector.class);
result = wrapper;
- wrapper.getValueVector();
- result = new IntVector(null, null);
+ wrapper.getValueVector();
+ result = new IntVector(null, null);
}
};
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/GeneratorFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/GeneratorFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/GeneratorFunctions.java
index 738d7f4..6d7da12 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/GeneratorFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/GeneratorFunctions.java
@@ -17,6 +17,7 @@
*/
package org.apache.drill.exec.fn.impl;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
@@ -28,7 +29,7 @@ import org.apache.drill.exec.record.RecordBatch;
import java.util.Random;
-public class GeneratorFunctions {
+public class GeneratorFunctions extends ExecTest {
public static final Random random = new Random(1234L);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java
index a23b31c..987661c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java
@@ -19,8 +19,6 @@
package org.apache.drill.exec.fn.impl;
import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-
import mockit.Injectable;
import mockit.NonStrictExpectations;
@@ -28,6 +26,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -46,7 +45,6 @@ import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.vector.BigIntVector;
import org.apache.drill.exec.vector.IntVector;
import org.apache.drill.exec.vector.Float8Vector;
-
import org.junit.Test;
import com.google.common.base.Charsets;
@@ -54,7 +52,7 @@ import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestMathFunctions {
+public class TestMathFunctions extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMathFunctions.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java
index 11b6890..c8b58cb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java
@@ -26,6 +26,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -48,66 +49,66 @@ import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
-public class TestRepeatedFunction {
+public class TestRepeatedFunction extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRepeatedFunction.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
// System.out.println(System.getProperty("java.class.path"));
-
+
new NonStrictExpectations(){{
bitContext.getMetrics(); result = new MetricRegistry();
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
+
boolean oneIsOne = false;
int size = 0;
int[] sizes = {1,2,0,6};
-
+
while(exec.next()){
IntVector c1 = exec.getValueVectorById(new SchemaPath("cnt", ExpressionPosition.UNKNOWN), IntVector.class);
BitVector c2 = exec.getValueVectorById(new SchemaPath("has_min", ExpressionPosition.UNKNOWN), BitVector.class);
-
+
for(int i =0; i < exec.getRecordCount(); i++){
int curSize = sizes[size % sizes.length];
assertEquals(curSize, c1.getAccessor().get(i));
switch(curSize){
- case 1:
+ case 1:
assertEquals(oneIsOne, 1 == c2.getAccessor().get(i));
oneIsOne = !oneIsOne;
break;
- case 2:
+ case 2:
assertEquals(1, c2.getAccessor().get(i));
break;
- case 0:
+ case 0:
assertEquals(0, c2.getAccessor().get(i));
break;
- case 6:
+ case 6:
assertEquals(1, c2.getAccessor().get(i));
break;
}
size++;
}
}
-
+
if(context.getFailureCause() != null){
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
-
+
@AfterClass
public static void tearDown() throws Exception{
// pause to get logger to catch up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java
index 8e53f30..d94b53a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java
@@ -20,13 +20,14 @@ package org.apache.drill.exec.memory;
import static org.junit.Assert.assertEquals;
import io.netty.buffer.ByteBuf;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.junit.Test;
-public class TestEndianess {
-
+public class TestEndianess extends ExecTest{
+
@Test
public void testLittleEndian(){
TopLevelAllocator a = new TopLevelAllocator(Long.MAX_VALUE);
@@ -37,5 +38,5 @@ public class TestEndianess {
assertEquals((int) b.getByte(2), 0);
assertEquals((int) b.getByte(3), 0);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/opt/BasicOptimizerTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/opt/BasicOptimizerTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/opt/BasicOptimizerTest.java
index 8f109c6..71e5d48 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/opt/BasicOptimizerTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/opt/BasicOptimizerTest.java
@@ -20,16 +20,10 @@ package org.apache.drill.exec.opt;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.logical.LogicalPlan;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.junit.Test;
-/**
- * Created with IntelliJ IDEA.
- * User: jaltekruse
- * Date: 6/12/13
- * Time: 12:09 PM
- * To change this template use File | Settings | File Templates.
- */
-public class BasicOptimizerTest {
+public class BasicOptimizerTest extends ExecTest {
@Test
public void parseSimplePlan() throws Exception{
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/config/TestParsePhysicalPlan.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/config/TestParsePhysicalPlan.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/config/TestParsePhysicalPlan.java
index 02a99e0..4ad181f 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/config/TestParsePhysicalPlan.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/config/TestParsePhysicalPlan.java
@@ -19,6 +19,7 @@ package org.apache.drill.exec.physical.config;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.physical.PhysicalPlan;
import org.apache.drill.exec.planner.PhysicalPlanReader;
import org.apache.drill.exec.proto.CoordinationProtos;
@@ -29,11 +30,11 @@ import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
-public class TestParsePhysicalPlan {
+public class TestParsePhysicalPlan extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestParsePhysicalPlan.class);
-
-
- @Test
+
+
+ @Test
public void parseSimplePlan() throws Exception{
DrillConfig c = DrillConfig.create();
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java
index ba4c561..1afb956 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java
@@ -25,6 +25,7 @@ import mockit.Injectable;
import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -43,7 +44,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class TestComparisonFunctions {
+public class TestComparisonFunctions extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestComparisonFunctions.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestHiveUDFs.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestHiveUDFs.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestHiveUDFs.java
index eb9bd0e..dff69e1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestHiveUDFs.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestHiveUDFs.java
@@ -23,6 +23,7 @@ import mockit.Injectable;
import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -49,7 +50,7 @@ import com.google.common.io.Resources;
import java.util.Iterator;
-public class TestHiveUDFs {
+public class TestHiveUDFs extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestHiveUDFs.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
index a8140b9..4a849d1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java
@@ -23,6 +23,7 @@ import mockit.Injectable;
import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -41,7 +42,7 @@ import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
-public class TestImplicitCastFunctions {
+public class TestImplicitCastFunctions extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestImplicitCastFunctions.class);
DrillConfig c = DrillConfig.create();
@@ -52,17 +53,17 @@ public class TestImplicitCastFunctions {
public Object[] getRunResult(SimpleRootExec exec) {
int size = 0;
for (ValueVector v : exec) {
- size++;
- }
-
+ size++;
+ }
+
Object[] res = new Object [size];
int i = 0;
for (ValueVector v : exec) {
res[i++] = v.getAccessor().getObject(0);
- }
+ }
return res;
}
-
+
public void runTest(@Injectable final DrillbitContext bitContext,
@Injectable UserServer.UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
@@ -79,15 +80,15 @@ public class TestImplicitCastFunctions {
PhysicalPlan plan = reader.readPhysicalPlan(planString);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
- while(exec.next()){
+
+ while(exec.next()){
Object [] res = getRunResult(exec);
assertEquals("return count does not match", res.length, expectedResults.length);
-
+
for (int i = 0; i<res.length; i++) {
assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
}
- }
+ }
if(context.getFailureCause() != null){
throw context.getFailureCause();
@@ -98,7 +99,7 @@ public class TestImplicitCastFunctions {
@Test
public void testImplicitCastWithConstant(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[21];
expected [0] = new Double (30.1);
expected [1] = new Double (30.1);
@@ -113,32 +114,32 @@ public class TestImplicitCastFunctions {
expected [9] = new Float (30.1);
expected [10] = new Double (30.1);
expected [11] = new Double (30.1);
-
+
expected [12] = new Float (30.1);
expected [13] = new Double (30.1);
expected [14] = new Float (30.1);
expected [15] = new Double (30.1);
-
+
expected [16] = Boolean.TRUE;
expected [17] = Boolean.TRUE;
expected [18] = Boolean.TRUE;
expected [19] = Boolean.TRUE;
expected [20] = Boolean.TRUE;
-
- runTest(bitContext, connection, expected, "functions/cast/testICastConstant.json");
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastConstant.json");
}
@Test
public void testImplicitCastWithMockColumn(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[5];
expected [0] = new Integer (0);
expected [1] = new Integer (0);
expected [2] = new Float (-4.2949673E9);
expected [3] = new Float (-4.2949673E9);
expected [4] = new Double (-9.223372036854776E18);
-
- runTest(bitContext, connection, expected, "functions/cast/testICastMockCol.json");
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastMockCol.json");
}
@AfterClass
@@ -146,25 +147,25 @@ public class TestImplicitCastFunctions {
// pause to get logger to catch up.
Thread.sleep(1000);
}
-
+
@Test
public void testImplicitCastWithNullExpression(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[10];
-
+
expected [0] = Boolean.TRUE;
expected [1] = Boolean.FALSE;
expected [2] = Boolean.FALSE;
expected [3] = Boolean.TRUE;
-
+
expected [4] = null;
expected [5] = null;
expected [6] = null;
expected [7] = null;
expected [8] = null;
expected [9] = null;
-
- runTest(bitContext, connection, expected, "functions/cast/testICastNullExp.json");
+
+ runTest(bitContext, connection, expected, "functions/cast/testICastNullExp.json");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java
index f1d6c03..4b2378d 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java
@@ -25,6 +25,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.logical.LogicalPlan;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.cache.DistributedCache;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.coord.ClusterCoordinator;
@@ -69,7 +70,7 @@ import com.google.common.io.Files;
import com.google.common.io.Resources;
@Ignore
-public class TestOptiqPlans {
+public class TestOptiqPlans extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestOptiqPlans.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
index 2206243..b2c278c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
@@ -30,6 +30,7 @@ import org.apache.drill.common.expression.*;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.Types;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.DrillFuncHolder;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.expr.holders.NullableVarBinaryHolder;
@@ -58,7 +59,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-public class TestSimpleFunctions {
+public class TestSimpleFunctions extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleFunctions.class);
DrillConfig c = DrillConfig.create();
@@ -263,7 +264,7 @@ public class TestSimpleFunctions {
assertTrue(!context.isFailed());
}
-
+
@After
public void tearDown() throws Exception{
// pause to get logger to catch up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java
index c85b9b4..09d1361 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java
@@ -27,6 +27,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.expr.holders.BigIntHolder;
import org.apache.drill.exec.expr.holders.VarCharHolder;
@@ -53,7 +54,7 @@ import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class TestStringFunctions {
+public class TestStringFunctions extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestStringFunctions.class);
DrillConfig c = DrillConfig.create();
@@ -64,9 +65,9 @@ public class TestStringFunctions {
public Object[] getRunResult(SimpleRootExec exec) {
int size = 0;
for (ValueVector v : exec) {
- size++;
- }
-
+ size++;
+ }
+
Object[] res = new Object [size];
int i = 0;
for (ValueVector v : exec) {
@@ -74,10 +75,10 @@ public class TestStringFunctions {
res[i++] = new String( ((VarCharVector) v).getAccessor().get(0));
} else
res[i++] = v.getAccessor().getObject(0);
- }
+ }
return res;
}
-
+
public void runTest(@Injectable final DrillbitContext bitContext,
@Injectable UserServer.UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
@@ -94,15 +95,15 @@ public class TestStringFunctions {
PhysicalPlan plan = reader.readPhysicalPlan(planString);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
- while(exec.next()){
+
+ while(exec.next()){
Object [] res = getRunResult(exec);
assertEquals("return count does not match", res.length, expectedResults.length);
-
+
for (int i = 0; i<res.length; i++) {
assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
}
- }
+ }
if(context.getFailureCause() != null){
throw context.getFailureCause();
@@ -113,134 +114,134 @@ public class TestStringFunctions {
@Test
public void testCharLength(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {new Long(8), new Long(0), new Long(5), new Long(5),
new Long(8), new Long(0), new Long(5), new Long(5),
new Long(8), new Long(0), new Long(5), new Long(5),};
-
- runTest(bitContext, connection, expected, "functions/string/testCharLength.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testCharLength.json");
}
-
+
@Test
public void testLike(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE};
-
- runTest(bitContext, connection, expected, "functions/string/testLike.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testLike.json");
}
@Test
public void testSimilar(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE};
-
- runTest(bitContext, connection, expected, "functions/string/testSimilar.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testSimilar.json");
}
-
+
@Test
public void testLtrim(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"def", "abcdef", "dabc", "", "", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testLtrim.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testLtrim.json");
}
@Test
public void testReplace(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"aABABcdf", "ABABbABbcdf", "aababcdf", "acdf", "ABCD", "abc"};
-
- runTest(bitContext, connection, expected, "functions/string/testReplace.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testReplace.json");
}
@Test
public void testRtrim(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"abc", "abcdef", "ABd", "", "", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testRtrim.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testRtrim.json");
}
@Test
public void testConcat(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"abcABC", "abc", "ABC", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testConcat.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testConcat.json");
}
@Test
public void testLower(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"abcefgh", "abc", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testLower.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testLower.json");
}
@Test
public void testPosition(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {new Long(2), new Long(0), new Long(0), new Long(0),
new Long(2), new Long(0), new Long(0), new Long(0)};
-
- runTest(bitContext, connection, expected, "functions/string/testPosition.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testPosition.json");
}
-
+
@Test
public void testRight(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"ef", "abcdef", "abcdef", "cdef", "f", "", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testRight.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testRight.json");
}
-
+
@Test
public void testSubstr(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"abc", "bcd", "bcdef", "bcdef", "", "", "", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testSubstr.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testSubstr.json");
}
-
+
@Test
public void testLeft(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"ab", "abcdef", "abcdef", "abcd", "a", "", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testLeft.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testLeft.json");
}
@Test
public void testLpad(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"", "", "abcdef", "ab", "ab", "abcdef", "AAAAabcdef", "ABABabcdef", "ABCAabcdef", "ABCDabcdef"};
-
- runTest(bitContext, connection, expected, "functions/string/testLpad.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testLpad.json");
}
@Test
public void testRegexpReplace(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"ThM", "Th", "Thomas"};
-
- runTest(bitContext, connection, expected, "functions/string/testRegexpReplace.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testRegexpReplace.json");
}
@Test
public void testRpad(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"", "", "abcdef", "ef", "ef", "abcdef", "abcdefAAAA", "abcdefABAB", "abcdefABCA", "abcdefABCD"};
-
- runTest(bitContext, connection, expected, "functions/string/testRpad.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testRpad.json");
}
@Test
public void testUpper(@Injectable final DrillbitContext bitContext,
- @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
Object [] expected = new Object[] {"ABCEFGH", "ABC", ""};
-
- runTest(bitContext, connection, expected, "functions/string/testUpper.json");
+
+ runTest(bitContext, connection, expected, "functions/string/testUpper.json");
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
index 938a479..94e15f6 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
@@ -25,6 +25,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -49,7 +50,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestAgg {
+public class TestAgg extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestAgg.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/common/TestHashTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/common/TestHashTable.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/common/TestHashTable.java
index 02bb60c..6eb468c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/common/TestHashTable.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/common/TestHashTable.java
@@ -27,6 +27,7 @@ import org.apache.drill.common.expression.FieldReference;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.data.NamedExpression;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.expr.holders.IntHolder;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -49,7 +50,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestHashTable {
+public class TestHashTable extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestHashTable.class);
DrillConfig c = DrillConfig.create();
@@ -70,7 +71,7 @@ private SimpleRootExec doTest(final DrillbitContext bitContext, UserClientConnec
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
return exec;
}
-/*
+/*
@Test
public void testHashTable1(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
String plan_path = "/common/test_hashtable1.json";
@@ -78,7 +79,7 @@ private SimpleRootExec doTest(final DrillbitContext bitContext, UserClientConnec
SchemaPath regionkey = new SchemaPath("regionkey", ExpressionPosition.UNKNOWN);
SchemaPath nationkey = new SchemaPath("nationkey", ExpressionPosition.UNKNOWN);
-
+
NamedExpression[] keyExprs = new NamedExpression[1];
keyExprs[0] = new NamedExpression(regionkey, new FieldReference(regionkey));
@@ -89,7 +90,7 @@ private SimpleRootExec doTest(final DrillbitContext bitContext, UserClientConnec
for (int i = 0; i < exec.getRecordCount(); i++) {
HashTable.PutStatus putStatus = htable.put(i, htIdxHolder);
- assertNotEquals(putStatus, HashTable.PutStatus.PUT_FAILED);
+ assertNotEquals(putStatus, HashTable.PutStatus.PUT_FAILED);
}
assertEquals(htable.size(), 5);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java
index e2b561c..c6632cb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java
@@ -23,6 +23,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -46,23 +47,23 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestSimpleFilter {
+public class TestSimpleFilter extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleFilter.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
// System.out.println(System.getProperty("java.class.path"));
-
+
new NonStrictExpectations(){{
bitContext.getMetrics(); result = new MetricRegistry();
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/filter/test1.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
@@ -71,7 +72,7 @@ public class TestSimpleFilter {
while(exec.next()){
assertEquals(50, exec.getRecordCount());
}
-
+
if(context.getFailureCause() != null){
throw context.getFailureCause();
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java
index 2d74fa9..9c36701 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java
@@ -27,6 +27,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -50,7 +51,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class TestSimpleLimit {
+public class TestSimpleLimit extends ExecTest {
DrillConfig c = DrillConfig.create();
@Test
@@ -87,9 +88,9 @@ public class TestSimpleLimit {
long start = 30000;
long end = 100000;
long expectedSum = (end - start) * (end + start - 1) / 2; //Formula for sum of series
-
+
verifySum(bitContext, connection, "test4.json", 70000, expectedSum);
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java
index 4d3941e..02bbdf9 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java
@@ -26,6 +26,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -50,11 +51,11 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestSimpleProjection {
+public class TestSimpleProjection extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleProjection.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void project(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
@@ -64,8 +65,8 @@ public class TestSimpleProjection {
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/project/test1.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
@@ -79,12 +80,12 @@ public class TestSimpleProjection {
BigIntVector.Accessor a1, a2;
a1 = c1.getAccessor();
a2 = c2.getAccessor();
-
+
for(int i =0; i < c1.getAccessor().getValueCount(); i++){
assertEquals(a1.get(i)+1, a2.get(i));
x += a1.get(i);
}
-
+
System.out.println(x);
}
@@ -93,7 +94,7 @@ public class TestSimpleProjection {
}
assertTrue(!context.isFailed());
}
-
+
@AfterClass
public static void tearDown() throws Exception{
// pause to get logger to catch up.
[05/10] git commit: DRILL-474: Long.MIN_VALUE is not parsed as BIGINT
but as a Double
Posted by ja...@apache.org.
DRILL-474: Long.MIN_VALUE is not parsed as BIGINT but as a Double
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/166079b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/166079b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/166079b2
Branch: refs/heads/master
Commit: 166079b2248f6e62d6cf105599e2e341f1f9868a
Parents: 1648195
Author: Aditya Kishore <ad...@maprtech.com>
Authored: Tue Apr 1 02:57:23 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu Apr 24 00:07:25 2014 -0700
----------------------------------------------------------------------
.../apache/drill/common/expression/parser/ExprParser.g | 6 +++---
.../apache/drill/common/expression/ValueExpressions.java | 11 ++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/166079b2/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
----------------------------------------------------------------------
diff --git a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
index 6788e56..ca37e4c 100644
--- a/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
+++ b/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
@@ -272,14 +272,14 @@ xorExpr returns [LogicalExpression e]
;
unaryExpr returns [LogicalExpression e]
- : Minus atom {$e = FunctionCallFactory.createExpression("u-", pos($atom.start), $atom.e); }
+ : sign=(Plus|Minus)? Number {$e = ValueExpressions.getNumericExpression($sign.text, $Number.text, pos(($sign != null) ? $sign : $Number)); }
+ | Minus atom {$e = FunctionCallFactory.createExpression("u-", pos($atom.start), $atom.e); }
| Excl atom {$e= FunctionCallFactory.createExpression("!", pos($atom.start), $atom.e); }
| atom {$e = $atom.e; }
;
atom returns [LogicalExpression e]
- : Number {$e = ValueExpressions.getNumericExpression($Number.text, pos($atom.start)); }
- | Bool {$e = new ValueExpressions.BooleanExpression( $Bool.text, pos($atom.start)); }
+ : Bool {$e = new ValueExpressions.BooleanExpression($Bool.text, pos($atom.start)); }
| lookup {$e = $lookup.e; }
;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/166079b2/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index 78f698c..0948c57 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -90,29 +90,30 @@ public class ValueExpressions {
return new Decimal38Expression(i, ExpressionPosition.UNKNOWN);
}
- public static LogicalExpression getNumericExpression(String s, ExpressionPosition ep) {
+ public static LogicalExpression getNumericExpression(String sign, String s, ExpressionPosition ep) {
+ String numStr = (sign == null) ? s : sign+s;
try {
- int a = Integer.parseInt(s);
+ int a = Integer.parseInt(numStr);
return new IntExpression(a, ep);
} catch (Exception e) {
}
try {
- long l = Long.parseLong(s);
+ long l = Long.parseLong(numStr);
return new LongExpression(l, ep);
} catch (Exception e) {
}
try {
- double d = Double.parseDouble(s);
+ double d = Double.parseDouble(numStr);
return new DoubleExpression(d, ep);
} catch (Exception e) {
}
throw new IllegalArgumentException(String.format("Unable to parse string %s as integer or floating point number.",
- s));
+ numStr));
}
[09/10] git commit: DRILL-514: improvements for unit tests on MapR
profile
Posted by ja...@apache.org.
DRILL-514: improvements for unit tests on MapR profile
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/c10ece07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/c10ece07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/c10ece07
Branch: refs/heads/master
Commit: c10ece07165988e354b2add40de067dd8e8dd437
Parents: 3a1e6c9
Author: Patrick Wong <pw...@maprtech.com>
Authored: Wed Apr 23 12:15:40 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu Apr 24 00:07:32 2014 -0700
----------------------------------------------------------------------
contrib/storage-hbase/pom.xml | 186 +++++++++++++++++++++++++------------
1 file changed, 128 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c10ece07/contrib/storage-hbase/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/pom.xml b/contrib/storage-hbase/pom.xml
index 4067f70..928ad4b 100644
--- a/contrib/storage-hbase/pom.xml
+++ b/contrib/storage-hbase/pom.xml
@@ -34,37 +34,6 @@
<artifactId>drill-java-exec</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.hbase</groupId>
- <artifactId>hbase</artifactId>
- <version>0.94.11</version>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-log4j12</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-log4j12</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>asm</artifactId>
- <groupId>asm</groupId>
- </exclusion>
- <exclusion>
- <artifactId>libthrift</artifactId>
- <groupId>org.apache.thrift</groupId>
- </exclusion>
- <exclusion>
- <artifactId>jruby-complete</artifactId>
- <groupId>org.jruby</groupId>
- </exclusion>
- </exclusions>
- </dependency>
<!-- Test dependencies -->
<dependency>
@@ -82,33 +51,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-test</artifactId>
- <version>1.2.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.hbase</groupId>
- <artifactId>hbase</artifactId>
- <classifier>tests</classifier>
- <version>0.94.11</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-log4j12</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>asm</artifactId>
- <groupId>asm</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>com.yammer.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>2.1.1</version>
@@ -132,4 +74,132 @@
</plugin>
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>default-hadoop</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase</artifactId>
+ <version>0.94.11</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>asm</artifactId>
+ <groupId>asm</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>libthrift</artifactId>
+ <groupId>org.apache.thrift</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jruby-complete</artifactId>
+ <groupId>org.jruby</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-test</artifactId>
+ <version>1.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase</artifactId>
+ <classifier>tests</classifier>
+ <version>0.94.11</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>asm</artifactId>
+ <groupId>asm</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>mapr</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase</artifactId>
+ <version>0.94.13-mapr-1401-m7-3.0.2</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>asm</artifactId>
+ <groupId>asm</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>libthrift</artifactId>
+ <groupId>org.apache.thrift</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jruby-complete</artifactId>
+ <groupId>org.jruby</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-test</artifactId>
+ <version>1.0.3-mapr-3.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase</artifactId>
+ <classifier>tests</classifier>
+ <version>0.94.13-mapr-1401-m7-3.0.2</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>asm</artifactId>
+ <groupId>asm</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
</project>
[06/10] DRILL-452: Conversion functions for external data types
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/test/resources/functions/conv/conversionTestWithLogicalPlan.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/conv/conversionTestWithLogicalPlan.json b/exec/java-exec/src/test/resources/functions/conv/conversionTestWithLogicalPlan.json
new file mode 100644
index 0000000..d137f85
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/conv/conversionTestWithLogicalPlan.json
@@ -0,0 +1,61 @@
+{
+ head: {
+ version: 1,
+ generator: {
+ type: "org.apache.drill.exec.planner.logical.DrillImplementor",
+ info: ""
+ },
+ type: "APACHE_DRILL_LOGICAL",
+ resultMode: "EXEC"
+ },
+ storage: {
+ mock : {
+ type : "mock"
+ }
+ },
+ query: [{
+ op: "scan",
+ @id: 1,
+ storageengine: "mock",
+ selection: [
+ {
+ records : 10,
+ types : [
+ {name : "tinyint_val", type : "TINYINT", mode : "REQUIRED"},
+ {name : "smallint_val", type : "SMALLINT", mode : "REQUIRED"},
+ {name : "int_val", type : "INT", mode : "REQUIRED"},
+ {name : "bigint_val", type : "BIGINT", mode : "REQUIRED"},
+ {name : "uint8_val", type : "UINT8", mode : "REQUIRED"}
+ ]
+ }]
+ },
+ {
+ op: "project",
+ @id: 2,
+ input: 1,
+ projections: [
+ {ref: "col_tinyint", expr: "convert_from(convert_to(tinyint_val, 'TINYINT_BE'), 'TINYINT_BE')"},
+ {ref: "col_smallint", expr: "convert_from(convert_to(smallint_val, 'SMALLINT'), 'SMALLINT')"},
+ {ref: "col_int", expr: "convert_from(convert_to(int_val, 'INT'), 'INT')"},
+ {ref: "col_bigint", expr: "convert_from(convert_to(bigint_val, 'BIGINT'), 'BIGINT')"},
+ {ref: "col_uint8", expr: "convert_from(convert_to(uint8_val, 'UINT8'), 'UINT8')"},
+ {ref: "col_smallint_be", expr: "convert_from(convert_to(smallint_val, 'SMALLINT_BE'), 'SMALLINT_BE')"},
+ {ref: "col_int_be", expr: "convert_from(convert_to(int_val, 'INT_BE'), 'INT_BE')"},
+ {ref: "col_bigint_be", expr: "convert_from(convert_to(bigint_val, 'BIGINT_BE'), 'BIGINT_BE')"}
+ ]
+ },
+ {
+ op: "limit",
+ @id: 3,
+ input: 2,
+ first: 0,
+ last: 10
+ },
+ {
+ op: "store",
+ @id: 4,
+ input: 3,
+ target: null,
+ storageEngine: "--SCREEN--"
+ }]
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/test/resources/functions/conv/conversionTestWithPhysicalPlan.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/conv/conversionTestWithPhysicalPlan.json b/exec/java-exec/src/test/resources/functions/conv/conversionTestWithPhysicalPlan.json
new file mode 100644
index 0000000..08b3c64
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/conv/conversionTestWithPhysicalPlan.json
@@ -0,0 +1,36 @@
+{
+ head: {
+ version: 1,
+ generator: {
+ type: "org.apache.drill.exec.planner.logical.DrillImplementor",
+ info: ""
+ },
+ type: "APACHE_DRILL_PHYSICAL",
+ resultMode: "EXEC"
+ },
+ graph: [{
+ @id: 1,
+ pop:"mock-sub-scan",
+ url: "http://apache.org",
+ entries: [{
+ records: 1,
+ types: [
+ {name: "tinyint_val", type: "TINYINT", mode: "REQUIRED"},
+ {name: "smallint_val", type: "SMALLINT", mode: "REQUIRED"},
+ {name: "int_val", type: "INT", mode: "REQUIRED"},
+ {name: "bigint_val", type: "BIGINT", mode: "REQUIRED"},
+ {name: "uint8_val", type: "UINT8", mode: "REQUIRED"}
+ ]
+ }]
+ },
+ {
+ pop: "project", @id: 2, child: 1,
+ exprs: [{ref: "testColumn", expr: "__CONVERT_EXPRESSION__"}]
+ },
+ {
+ pop: "selection-vector-remover", @id:3, child: 2
+ },
+ {
+ pop: "screen", @id: 4, child: 3
+ }]
+}
[10/10] git commit: Fixes for DRILL-514,
increase HashJoin timeout and cleanup PopUnitTestBase
Posted by ja...@apache.org.
Fixes for DRILL-514, increase HashJoin timeout and cleanup PopUnitTestBase
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/9906e06e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/9906e06e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/9906e06e
Branch: refs/heads/master
Commit: 9906e06e0ded610059226f1934025611063bcfaf
Parents: c10ece0
Author: Jacques Nadeau <ja...@apache.org>
Authored: Thu Apr 24 00:06:59 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu Apr 24 00:07:41 2014 -0700
----------------------------------------------------------------------
contrib/storage-hbase/pom.xml | 9 +++++++++
.../apache/drill/exec/physical/impl/join/TestHashJoin.java | 8 ++++++++
.../java/org/apache/drill/exec/pop/PopUnitTestBase.java | 5 -----
3 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/9906e06e/contrib/storage-hbase/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/pom.xml b/contrib/storage-hbase/pom.xml
index 928ad4b..38f8a1a 100644
--- a/contrib/storage-hbase/pom.xml
+++ b/contrib/storage-hbase/pom.xml
@@ -77,6 +77,11 @@
<profiles>
<profile>
<id>default-hadoop</id>
+ <activation>
+ <property>
+ <name>!alt-hadoop</name>
+ </property>
+ </activation>
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
@@ -140,6 +145,10 @@
</profile>
<profile>
<id>mapr</id>
+ <properties>
+ <alt-hadoop>mapr</alt-hadoop>
+ <rat.excludeSubprojects>true</rat.excludeSubprojects>
+ </properties>
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/9906e06e/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java
index 529563a..ba067e2 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java
@@ -28,6 +28,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.common.util.TestTools;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -47,12 +48,14 @@ import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.vector.ValueVector;
import org.junit.AfterClass;
+import org.junit.Rule;
import org.junit.Test;
import com.beust.jcommander.internal.Lists;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
+
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -75,6 +78,9 @@ import org.apache.drill.exec.vector.VarCharVector;
import org.apache.drill.exec.vector.IntVector;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
@@ -83,6 +89,8 @@ import com.google.common.io.Files;
public class TestHashJoin extends PopUnitTestBase{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMergeJoin.class);
+ @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(100000);
+
DrillConfig c = DrillConfig.create();
private void testHJMockScanCommon(final DrillbitContext bitContext, UserServer.UserClientConnection connection, String physicalPlan, int expectedRows) throws Throwable {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/9906e06e/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
index 79bdbae..f19d616 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
@@ -41,13 +41,8 @@ import com.google.common.io.Files;
public abstract class PopUnitTestBase extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PopUnitTestBase.class);
- // Determine if we are in Eclipse Debug mode.
- static final boolean IS_DEBUG = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
protected static DrillConfig CONFIG;
- // Set a timeout unless we're debugging.
- @Rule public TestRule globalTimeout = IS_DEBUG ? new TestName() : new Timeout(500000);
-
@BeforeClass
public static void setup() {
CONFIG = DrillConfig.create();
[07/10] DRILL-452: Conversion functions for external data types
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
new file mode 100644
index 0000000..3ad2d81
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromSMALLINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class SmallIntBEConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output SmallIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
+
+ in.buffer.readerIndex(in.start);
+ out.value = Short.reverseBytes(in.buffer.readShort());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
new file mode 100644
index 0000000..c22cad1
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toSMALLINT_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class SmallIntBEConvertTo implements DrillSimpleFunc {
+
+ @Param SmallIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(2);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeShort(Short.reverseBytes(in.value));
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
new file mode 100644
index 0000000..6d4832b
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromSMALLINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class SmallIntConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output SmallIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readShort();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
new file mode 100644
index 0000000..3443ec3
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toSMALLINT", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class SmallIntConvertTo implements DrillSimpleFunc {
+
+ @Param SmallIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(2);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeShort(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
new file mode 100644
index 0000000..c426d28
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.TimeHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromTIME_EPOCH_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TimeEpochBEConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output TimeHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ long epochMillis = Long.reverseBytes(in.buffer.readLong());
+ out.value = (int) (epochMillis % (24*3600*1000));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
new file mode 100644
index 0000000..66a5e84
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.TimeHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toTIME_EPOCH_BE", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TimeEpochBEConvertTo implements DrillSimpleFunc {
+
+ @Param TimeHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(Integer.reverseBytes(in.value));
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
new file mode 100644
index 0000000..aa23050
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.TimeHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromTIME_EPOCH", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TimeEpochConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output TimeHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ long epochMillis = in.buffer.readLong();
+ out.value = (int) (epochMillis % (24*3600*1000));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
new file mode 100644
index 0000000..b97c604
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.TimeHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toTIME_EPOCH", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TimeEpochConvertTo implements DrillSimpleFunc {
+
+ @Param TimeHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
new file mode 100644
index 0000000..367fd6b
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.TinyIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(names = {"convert_fromTINYINT", "convert_fromTINYINT_BE"},
+ scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TinyIntConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output TinyIntHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readByte();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
new file mode 100644
index 0000000..3a58105
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.TinyIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(names = {"convert_toTINYINT", "convert_toTINYINT_BE"},
+ scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class TinyIntConvertTo implements DrillSimpleFunc {
+
+ @Param TinyIntHolder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(1);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeByte(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
new file mode 100644
index 0000000..83fddc9
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.UInt8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromUINT8", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UInt8ConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Output UInt8Holder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+
+ in.buffer.readerIndex(in.start);
+ out.value = in.buffer.readLong();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
new file mode 100644
index 0000000..4e4d84d
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.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.drill.exec.expr.fn.impl.conv;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.UInt8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toUINT8", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UInt8ConvertTo implements DrillSimpleFunc {
+
+ @Param UInt8Holder in;
+ @Output VarBinaryHolder out;
+ @Workspace ByteBuf buffer;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ }
+
+ @Override
+ public void eval() {
+ buffer.clear();
+ buffer.writeLong(in.value);
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = 8;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertFrom.java
new file mode 100644
index 0000000..d8dfe26
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertFrom.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.Var16CharHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromUTF16", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UTF16ConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Param BigIntHolder length;
+ @Output Var16CharHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.buffer = in.buffer;
+ out.start = in.start;
+ if (in.end - in.start <= length.value) {
+ out.end = in.end;
+ } else {
+ out.end = out.start + (int) length.value;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertTo.java
new file mode 100644
index 0000000..b47918b
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF16ConvertTo.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.Var16CharHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toUTF16", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UTF16ConvertTo implements DrillSimpleFunc {
+
+ @Param Var16CharHolder in;
+ @Param BigIntHolder length;
+ @Output VarBinaryHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.buffer = in.buffer;
+ out.start = in.start;
+ if (in.end - in.start <= length.value) {
+ out.end = in.end;
+ } else {
+ out.end = out.start + (int) length.value;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertFrom.java
new file mode 100644
index 0000000..b73ca98
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertFrom.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromUTF8", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UTF8ConvertFrom implements DrillSimpleFunc {
+
+ @Param VarBinaryHolder in;
+ @Param BigIntHolder length;
+ @Output VarCharHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.buffer = in.buffer;
+ out.start = in.start;
+ if (in.end - in.start <= length.value) {
+ out.end = in.end;
+ } else {
+ out.end = out.start + (int) length.value;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertTo.java
new file mode 100644
index 0000000..92770de
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UTF8ConvertTo.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.expr.fn.impl.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_toUTF8", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class UTF8ConvertTo implements DrillSimpleFunc {
+
+ @Param VarCharHolder in;
+ @Param BigIntHolder length;
+ @Output VarBinaryHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) { }
+
+ @Override
+ public void eval() {
+ out.buffer = in.buffer;
+ out.start = in.start;
+ if (in.end - in.start <= length.value) {
+ out.end = in.end;
+ } else {
+ out.end = out.start + (int) length.value;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
index 2d50846..3aab08f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
@@ -52,6 +52,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -76,6 +80,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -100,6 +108,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -124,6 +136,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -142,12 +158,44 @@ public class TypeCastRules {
rule.add(MinorType.VARBINARY);
rules.put(MinorType.BIGINT, rule);
+ /** UINT8 cast able from **/
+ rule = new HashSet<MinorType>();
+ rule.add(MinorType.TINYINT);
+ rule.add(MinorType.SMALLINT);
+ rule.add(MinorType.INT);
+ rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
+ rule.add(MinorType.DECIMAL9);
+ rule.add(MinorType.DECIMAL18);
+ rule.add(MinorType.DECIMAL28SPARSE);
+ rule.add(MinorType.DECIMAL28DENSE);
+ rule.add(MinorType.DECIMAL38SPARSE);
+ rule.add(MinorType.DECIMAL38DENSE);
+ rule.add(MinorType.MONEY);
+ rule.add(MinorType.FLOAT4);
+ rule.add(MinorType.FLOAT8);
+ rule.add(MinorType.BIT);
+ rule.add(MinorType.FIXEDCHAR);
+ rule.add(MinorType.FIXED16CHAR);
+ rule.add(MinorType.FIXEDBINARY);
+ rule.add(MinorType.VARCHAR);
+ rule.add(MinorType.VAR16CHAR);
+ rule.add(MinorType.VARBINARY);
+ rules.put(MinorType.UINT8, rule);
+
/** DECIMAL9 cast able from **/
rule = new HashSet<MinorType>();
rule.add(MinorType.TINYINT);
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -172,6 +220,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -196,6 +248,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -220,6 +276,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -244,6 +304,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -269,6 +333,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -293,6 +361,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -344,6 +416,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -423,6 +499,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -444,6 +524,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -466,6 +550,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -493,6 +581,10 @@ public class TypeCastRules {
rule.add(MinorType.BIGINT);
rule.add(MinorType.MONEY);
rule.add(MinorType.TIMESTAMPTZ);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -524,6 +616,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -556,6 +652,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -579,6 +679,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -611,6 +715,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
@@ -643,6 +751,10 @@ public class TypeCastRules {
rule.add(MinorType.SMALLINT);
rule.add(MinorType.INT);
rule.add(MinorType.BIGINT);
+ rule.add(MinorType.UINT1);
+ rule.add(MinorType.UINT2);
+ rule.add(MinorType.UINT4);
+ rule.add(MinorType.UINT8);
rule.add(MinorType.DECIMAL9);
rule.add(MinorType.DECIMAL18);
rule.add(MinorType.DECIMAL28SPARSE);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
index d203fa4..cff075c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
@@ -202,7 +202,7 @@ public class HiveRecordReader implements RecordReader {
}
for (int i = 0; i < selectedPartitionNames.size(); i++) {
String type = selectedPartitionTypes.get(i);
- MaterializedField field = MaterializedField.create(SchemaPath.getSimplePath(columnNames.get(i)), getMajorType(type));
+ MaterializedField field = MaterializedField.create(SchemaPath.getSimplePath(columnNames.get(i)), Types.getMajorTypeFromName(type));
ValueVector vv = TypeHelper.getNewVector(field, context.getAllocator());
pVectors.add(vv);
output.addField(vv);
@@ -317,35 +317,6 @@ public class HiveRecordReader implements RecordReader {
}
}
- public static TypeProtos.MajorType getMajorType(String type) {
- switch(type) {
- case "binary":
- return Types.required(TypeProtos.MinorType.VARBINARY);
- case "boolean":
- return Types.required(TypeProtos.MinorType.BIT);
- case "tinyint":
- return Types.required(TypeProtos.MinorType.TINYINT);
- case "decimal":
- return Types.required(TypeProtos.MinorType.DECIMAL38SPARSE);
- case "double":
- return Types.required(TypeProtos.MinorType.FLOAT8);
- case "float":
- return Types.required(TypeProtos.MinorType.FLOAT4);
- case "int":
- return Types.required(TypeProtos.MinorType.INT);
- case "bigint":
- return Types.required(TypeProtos.MinorType.BIGINT);
- case "smallint":
- return Types.required(TypeProtos.MinorType.SMALLINT);
- case "string":
- return Types.required(TypeProtos.MinorType.VARCHAR);
- case "varchar":
-
- default:
- throw new UnsupportedOperationException("Could not determine type: " + type);
- }
- }
-
public static TypeProtos.MajorType getMajorType(PrimitiveCategory pCat) {
switch(pCat) {
case BINARY:
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
new file mode 100644
index 0000000..750885c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
@@ -0,0 +1,209 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.util;
+
+import static java.nio.ByteOrder.LITTLE_ENDIAN;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import java.io.DataInput;
+
+import org.apache.drill.exec.expr.fn.impl.StringFunctionUtil;
+
+public class ConvertUtil {
+ /**
+ * Creates a wrapped {@link ByteBuf} of {@code size} number of bytes with
+ * the Drill's default endianness(LITTLE_ENDIAN).
+ *
+ * @param size
+ * @return
+ */
+ public static ByteBuf createBuffer(int size) {
+ return Unpooled.wrappedBuffer(new byte[size]).order(LITTLE_ENDIAN);
+ }
+
+ /**
+ * Verifies that the the space provided in the buffer is of specified size.
+ * @throws IllegalArgumentException if the specified boundaries do not describe the expected size.
+ */
+ public static void checkBufferLength(ByteBuf buffer, int start, int end, int requiredLen) {
+ int actualLen = (end - start);
+ if (actualLen != requiredLen) {
+ throw new IllegalArgumentException(String.format("Wrong length %d(%d-%d) in the buffer '%s', expected %d.",
+ actualLen, end, start, StringFunctionUtil.toBinaryString(buffer, start, end), requiredLen));
+ }
+ }
+
+ /**
+ * Modeled after {@code org.apache.hadoop.io.WritableUtils}.
+ * We copy the code to avoid wrapping {@link ByteBuf} to/from {@link DataInput}.
+ */
+ public static class HadoopWritables {
+ /**
+ * Serializes an integer to a binary stream with zero-compressed encoding.
+ * For -120 <= i <= 127, only one byte is used with the actual value.
+ * For other values of i, the first byte value indicates whether the
+ * integer is positive or negative, and the number of bytes that follow.
+ * If the first byte value v is between -121 and -124, the following integer
+ * is positive, with number of bytes that follow are -(v+120).
+ * If the first byte value v is between -125 and -128, the following integer
+ * is negative, with number of bytes that follow are -(v+124). Bytes are
+ * stored in the high-non-zero-byte-first order.
+ *
+ * @param buffer ByteBuf to read from
+ * @param i Integer to be serialized
+ */
+ public static void writeVInt(ByteBuf buffer, int start, int end, int i) {
+ writeVLong(buffer, start, end, i);
+ }
+
+ /**
+ * Serializes a long to a binary stream with zero-compressed encoding.
+ * For -112 <= i <= 127, only one byte is used with the actual value.
+ * For other values of i, the first byte value indicates whether the
+ * long is positive or negative, and the number of bytes that follow.
+ * If the first byte value v is between -113 and -120, the following long
+ * is positive, with number of bytes that follow are -(v+112).
+ * If the first byte value v is between -121 and -128, the following long
+ * is negative, with number of bytes that follow are -(v+120). Bytes are
+ * stored in the high-non-zero-byte-first order.
+ *
+ * @param buffer ByteBuf to write to
+ * @param i Long to be serialized
+ */
+ public static void writeVLong(ByteBuf buffer, int start, int end, long i) {
+ int availableBytes = (end-start);
+ if (availableBytes < getVIntSize(i)) {
+ throw new NumberFormatException("Expected " + getVIntSize(i) + " bytes but the buffer '"
+ + StringFunctionUtil.toBinaryString(buffer, start, end) + "' has only "
+ + availableBytes + " bytes.");
+ }
+ buffer.writerIndex(start);
+
+ if (i >= -112 && i <= 127) {
+ buffer.writeByte((byte)i);
+ return;
+ }
+
+ int len = -112;
+ if (i < 0) {
+ i ^= -1L; // take one's complement'
+ len = -120;
+ }
+
+ long tmp = i;
+ while (tmp != 0) {
+ tmp = tmp >> 8;
+ len--;
+ }
+
+ buffer.writeByte((byte)len);
+
+ len = (len < -120) ? -(len + 120) : -(len + 112);
+
+ for (int idx = len; idx != 0; idx--) {
+ int shiftbits = (idx - 1) * 8;
+ long mask = 0xFFL << shiftbits;
+ buffer.writeByte((byte)((i & mask) >> shiftbits));
+ }
+ }
+
+ /**
+ * Reads a zero-compressed encoded integer from input stream and returns it.
+ * @param buffer ByteBuf to read from
+ * @return deserialized integer from stream.
+ */
+ public static int readVInt(ByteBuf buffer, int start, int end) {
+ long n = readVLong(buffer, start, end);
+ if ((n > Integer.MAX_VALUE) || (n < Integer.MIN_VALUE)) {
+ throw new NumberFormatException("Value " + n + " too long to fit in integer");
+ }
+ return (int)n;
+ }
+
+ /**
+ * Reads a zero-compressed encoded long from input stream and returns it.
+ * @param buffer ByteBuf to read from
+ * @return deserialized long from stream.
+ */
+ public static long readVLong(ByteBuf buffer, int start, int end) {
+ buffer.readerIndex(start);
+ byte firstByte = buffer.readByte();
+ int len = decodeVIntSize(firstByte);
+ int availableBytes = (end-start);
+ if (len == 1) {
+ return firstByte;
+ } else if (availableBytes < len) {
+ throw new NumberFormatException("Expected " + len + " bytes but the buffer '"
+ + StringFunctionUtil.toBinaryString(buffer, start, end) + "' has "
+ + availableBytes + " bytes.");
+ }
+
+ long longValue = 0;
+ for (int idx = 0; idx < len-1; idx++) {
+ byte byteValue = buffer.readByte();
+ longValue = longValue << 8;
+ longValue = longValue | (byteValue & 0xFF);
+ }
+ return (isNegativeVInt(firstByte) ? (longValue ^ -1L) : longValue);
+ }
+
+ /**
+ * Parse the first byte of a vint/vlong to determine the number of bytes
+ * @param value the first byte of the vint/vlong
+ * @return the total number of bytes (1 to 9)
+ */
+ public static int decodeVIntSize(byte value) {
+ if (value >= -112) {
+ return 1;
+ } else if (value < -120) {
+ return -119 - value;
+ }
+ return -111 - value;
+ }
+
+ /**
+ * Get the encoded length if an integer is stored in a variable-length format
+ * @return the encoded length
+ */
+ public static int getVIntSize(long i) {
+ if (i >= -112 && i <= 127) {
+ return 1;
+ }
+
+ if (i < 0) {
+ i ^= -1L; // take one's complement'
+ }
+ // find the number of bytes with non-leading zeros
+ int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i);
+ // find the number of data bytes + length byte
+ return (dataBits + 7) / 8 + 1;
+ }
+
+ /**
+ * Given the first byte of a vint/vlong, determine the sign
+ * @param value the first byte
+ * @return is the value negative
+ */
+ public static boolean isNegativeVInt(byte value) {
+ return value < -120 || (value >= -112 && value < 0);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3a1e6c9f/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
new file mode 100644
index 0000000..881495c
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
@@ -0,0 +1,498 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.physical.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import io.netty.buffer.ByteBuf;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import mockit.Injectable;
+import mockit.NonStrictExpectations;
+
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.physical.base.FragmentRoot;
+import org.apache.drill.exec.planner.PhysicalPlanReader;
+import org.apache.drill.exec.pop.PopUnitTestBase;
+import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.CoordinationProtos;
+import org.apache.drill.exec.proto.UserProtos.QueryType;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.rpc.user.QueryResultBatch;
+import org.apache.drill.exec.rpc.user.UserServer;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.util.ConvertUtil;
+import org.apache.drill.exec.util.ConvertUtil.HadoopWritables;
+import org.apache.drill.exec.util.VectorUtil;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.vector.VarCharVector;
+import org.junit.Test;
+
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+
+public class TestConvertFunctions extends PopUnitTestBase {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestConvertFunctions.class);
+
+ private static final String CONVERSION_TEST_LOGICAL_PLAN = "functions/conv/conversionTestWithLogicalPlan.json";
+ private static final String CONVERSION_TEST_PHYSICAL_PLAN = "functions/conv/conversionTestWithPhysicalPlan.json";
+
+ private static final float DELTA = (float) 0.0001;
+
+ private static final DateFormat DATE_FORMAT;
+ private static final DateFormat DATE_TIME_FORMAT;
+
+ // "1980-01-01 01:23:45.678"
+ private static final String DATE_TIME_BE = "\\x00\\x00\\x00\\x49\\x77\\x85\\x1f\\x8e";
+ private static final String DATE_TIME_LE = "\\x8e\\x1f\\x85\\x77\\x49\\x00\\x00\\x00";
+
+ private static Date time = null;
+ private static Date date = null;
+
+ static {
+ DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+ DATE_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");
+ try {
+ time = DATE_TIME_FORMAT.parse("01:23:45.678"); // 5025678
+ date = DATE_FORMAT.parse("1980-01-01"); // 0x4977387000
+ } catch (ParseException e) { }
+ }
+
+ DrillConfig c = DrillConfig.create();
+ PhysicalPlanReader reader;
+ FunctionImplementationRegistry registry;
+ FragmentContext context;
+ String textFileContent;
+
+ @Test
+ public void testDateTime1(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('" + DATE_TIME_BE + "'), 'TIME_EPOCH_BE')", time);
+ }
+
+ @Test
+ public void testDateTime2(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('" + DATE_TIME_LE + "'), 'TIME_EPOCH')", time);
+ }
+
+ @Test
+ public void testDateTime3(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('" + DATE_TIME_BE + "'), 'DATE_EPOCH_BE')", date );
+ }
+
+ @Test
+ public void testDateTime4(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('" + DATE_TIME_LE + "'), 'DATE_EPOCH')", date);
+ }
+
+ @Test
+ public void testFixedInts1(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xAD'), 'TINYINT')", (byte) 0xAD);
+ }
+
+ @Test
+ public void testFixedInts2(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xFE\\xCA'), 'SMALLINT')", (short) 0xCAFE);
+ }
+
+ @Test
+ public void testFixedInts3(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xCA\\xFE'), 'SMALLINT_BE')", (short) 0xCAFE);
+ }
+
+ @Test
+ public void testFixedInts4(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xBE\\xBA\\xFE\\xCA'), 'INT')", 0xCAFEBABE);
+ }
+
+ @Test
+ public void testFixedInts5(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xCA\\xFE\\xBA\\xBE'), 'INT_BE')", 0xCAFEBABE);
+ }
+
+ @Test
+ public void testFixedInts6(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xEF\\xBE\\xAD\\xDE\\xBE\\xBA\\xFE\\xCA'), 'BIGINT')", 0xCAFEBABEDEADBEEFL);
+ }
+
+ @Test
+ public void testFixedInts7(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\xCA\\xFE\\xBA\\xBE\\xDE\\xAD\\xBE\\xEF'), 'BIGINT_BE')", 0xCAFEBABEDEADBEEFL);
+ }
+
+ @Test
+ public void testFixedInts8(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(convert_to(cast(77 as varchar(2)), 'INT_BE'), 'INT_BE')", 77);
+ }
+
+ @Test
+ public void testFixedInts9(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(77 as varchar(2)), 'INT_BE')", new byte[] {0, 0, 0, 77});
+ }
+
+ @Test
+ public void testFixedInts10(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(77 as varchar(2)), 'INT')", new byte[] {77, 0, 0, 0});
+ }
+
+ @Test
+ public void testFixedInts11(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(77, 'BIGINT_BE')", new byte[] {0, 0, 0, 0, 0, 0, 0, 77});
+ }
+
+ @Test
+ public void testFixedInts12(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(9223372036854775807, 'BIGINT')", new byte[] {-1, -1, -1, -1, -1, -1, -1, 0x7f});
+ }
+
+ @Test
+ public void testFixedInts13(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(-9223372036854775808, 'BIGINT')", new byte[] {0, 0, 0, 0, 0, 0, 0, (byte)0x80});
+ }
+
+ @Test
+ public void testVInts1(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(0 as int), 'INT_HADOOPV')", new byte[] {0});
+ }
+
+ @Test
+ public void testVInts2(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(128 as int), 'INT_HADOOPV')", new byte[] {-113, -128});
+ }
+
+ @Test
+ public void testVInts3(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(256 as int), 'INT_HADOOPV')", new byte[] {-114, 1, 0});
+ }
+
+ @Test
+ public void testVInts4(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(65536 as int), 'INT_HADOOPV')", new byte[] {-115, 1, 0, 0});
+ }
+
+ @Test
+ public void testVInts5(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(16777216 as int), 'INT_HADOOPV')", new byte[] {-116, 1, 0, 0, 0});
+ }
+
+ @Test
+ public void testVInts6(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(4294967296, 'BIGINT_HADOOPV')", new byte[] {-117, 1, 0, 0, 0, 0});
+ }
+
+ @Test
+ public void testVInts7(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(1099511627776, 'BIGINT_HADOOPV')", new byte[] {-118, 1, 0, 0, 0, 0, 0});
+ }
+
+ @Test
+ public void testVInts8(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(281474976710656, 'BIGINT_HADOOPV')", new byte[] {-119, 1, 0, 0, 0, 0, 0, 0});
+ }
+
+ @Test
+ public void testVInts9(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(72057594037927936, 'BIGINT_HADOOPV')", new byte[] {-120, 1, 0, 0, 0, 0, 0, 0, 0});
+ }
+
+ @Test
+ public void testVInts10(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(9223372036854775807, 'BIGINT_HADOOPV')", new byte[] {-120, 127, -1, -1, -1, -1, -1, -1, -1});
+ }
+
+ @Test
+ public void testVInts11(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\x88\\x7f\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF'), 'BIGINT_HADOOPV')", 9223372036854775807L);
+ }
+
+ @Test
+ public void testVInts12(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(-9223372036854775808, 'BIGINT_HADOOPV')", new byte[] {-128, 127, -1, -1, -1, -1, -1, -1, -1});
+ }
+
+ @Test
+ public void testVInts13(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\x80\\x7f\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF'), 'BIGINT_HADOOPV')", -9223372036854775808L);
+ }
+
+ @Test
+ public void testBool1(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\x01'), 'BOOLEAN_BYTE')", true);
+ }
+
+ @Test
+ public void testBool2(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(binary_string('\\x00'), 'BOOLEAN_BYTE')", false);
+ }
+
+ @Test
+ public void testBool3(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(true, 'BOOLEAN_BYTE')", new byte[] {1});
+ }
+
+ @Test
+ public void testBool4(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(false, 'BOOLEAN_BYTE')", new byte[] {0});
+ }
+
+ @Test
+ public void testFloats1(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ }
+
+ @Test
+ public void testFloats2(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(convert_to(cast(77 as float4), 'FLOAT'), 'FLOAT')", new Float(77.0));
+ }
+
+ @Test
+ public void testFloats3(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(1.4e-45 as float4), 'FLOAT')", new byte[] {1, 0, 0, 0});
+ }
+
+ @Test
+ public void testFloats4(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(3.4028235e+38 as float4), 'FLOAT')", new byte[] {-1, -1, 127, 127});
+ }
+
+ @Test
+ public void testFloats5(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_from(convert_to(cast(77 as float8), 'DOUBLE'), 'DOUBLE')", 77.0);
+ }
+
+ @Test
+ public void testFloats6(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(cast(77 as float8), 'DOUBLE')", new byte[] {0, 0, 0, 0, 0, 64, 83, 64});
+ }
+
+ @Test
+ public void testFloats7(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(4.9e-324, 'DOUBLE')", new byte[] {1, 0, 0, 0, 0, 0, 0, 0});
+ }
+
+ @Test
+ public void testFloats8(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable {
+ runTest(bitContext, connection, "convert_to(1.7976931348623157e+308, 'DOUBLE')", new byte[] {-1, -1, -1, -1, -1, -1, -17, 127});
+ }
+
+ @Test
+ public void testBigIntVarCharReturnTripConvertLogical() throws Exception {
+ RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
+
+ try(Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
+ DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator());) {
+ bit1.run();
+ client.connect();
+ String logicalPlan = Resources.toString(Resources.getResource(CONVERSION_TEST_LOGICAL_PLAN), Charsets.UTF_8);
+ List<QueryResultBatch> results = client.runQuery(QueryType.LOGICAL, logicalPlan);
+ int count = 0;
+ RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator());
+ for(QueryResultBatch b : results){
+ count += b.getHeader().getRowCount();
+ loader.load(b.getHeader().getDef(), b.getData());
+ if (loader.getRecordCount() <= 0) {
+ break;
+ }
+ VectorUtil.showVectorAccessibleContent(loader);
+ }
+ assertTrue(count == 10);
+ }
+ }
+
+ @Test
+ public void testHadooopVInt() throws Exception {
+ final int _0 = 0;
+ final int _9 = 9;
+ final ByteBuf buffer = ConvertUtil.createBuffer(_9);
+
+ long longVal = 0;
+ buffer.clear();
+ HadoopWritables.writeVLong(buffer, _0, _9, 0);
+ longVal = HadoopWritables.readVLong(buffer, _0, _9);
+ assertEquals(longVal, 0);
+
+ buffer.clear();
+ HadoopWritables.writeVLong(buffer, _0, _9, Long.MAX_VALUE);
+ longVal = HadoopWritables.readVLong(buffer, _0, _9);
+ assertEquals(longVal, Long.MAX_VALUE);
+
+ buffer.clear();
+ HadoopWritables.writeVLong(buffer, _0, _9, Long.MIN_VALUE);
+ longVal = HadoopWritables.readVLong(buffer, _0, _9);
+ assertEquals(longVal, Long.MIN_VALUE);
+
+ int intVal = 0;
+ buffer.clear();
+ HadoopWritables.writeVInt(buffer, _0, _9, 0);
+ intVal = HadoopWritables.readVInt(buffer, _0, _9);
+ assertEquals(intVal, 0);
+
+ buffer.clear();
+ HadoopWritables.writeVInt(buffer, _0, _9, Integer.MAX_VALUE);
+ intVal = HadoopWritables.readVInt(buffer, _0, _9);
+ assertEquals(intVal, Integer.MAX_VALUE);
+
+ buffer.clear();
+ HadoopWritables.writeVInt(buffer, _0, _9, Integer.MIN_VALUE);
+ intVal = HadoopWritables.readVInt(buffer, _0, _9);
+ assertEquals(intVal, Integer.MIN_VALUE);
+ }
+
+ @SuppressWarnings("deprecation")
+ protected <T> void runTest(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection, String expression, T expectedResults) throws Throwable {
+
+ final BufferAllocator allocator = new TopLevelAllocator();
+ new NonStrictExpectations(){{
+ bitContext.getMetrics(); result = new MetricRegistry();
+ bitContext.getAllocator(); result = allocator;
+ bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
+ }};
+
+ String testName = String.format("Expression: %s.", expression);
+ expression = expression.replace("\\", "\\\\\\\\"); // "\\\\\\\\" => Java => "\\\\" => JsonParser => "\\" => AntlrParser "\"
+
+ if (textFileContent == null) textFileContent = Resources.toString(Resources.getResource(CONVERSION_TEST_PHYSICAL_PLAN), Charsets.UTF_8);
+ if(reader == null) reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
+ if(registry == null) registry = new FunctionImplementationRegistry(c);
+ if(context == null) context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
+
+ String planString = textFileContent.replace("__CONVERT_EXPRESSION__", expression);
+ PhysicalPlan plan = reader.readPhysicalPlan(planString);
+ SimpleRootExec exec = new SimpleRootExec(
+ ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
+
+ exec.next();
+ Object[] results = getRunResult(exec);
+ assertEquals(testName, 1, results.length);
+ assertNotNull(testName, results[0]);
+ if (expectedResults.getClass().isArray()) {
+ assertArraysEquals(testName, expectedResults, results[0]);
+ } else {
+ assertEquals(testName, expectedResults, results[0]);
+ }
+
+ allocator.close();
+
+ if(context.getFailureCause() != null){
+ throw context.getFailureCause();
+ }
+
+ assertTrue(!context.isFailed());
+ }
+
+ protected Object[] getRunResult(SimpleRootExec exec) {
+ Object[] res = new Object [exec.getRecordCount()];
+ int i = 0;
+ for (ValueVector v : exec) {
+ for (int j = 0; j < v.getAccessor().getValueCount(); j++) {
+ if (v instanceof VarCharVector) {
+ res[i++] = new String(((VarCharVector) v).getAccessor().get(j));
+ } else {
+ res[i++] = v.getAccessor().getObject(j);
+ }
+ }
+ break;
+ }
+ return res;
+ }
+
+ protected void assertArraysEquals(Object expected, Object actual) {
+ assertArraysEquals(null, expected, actual);
+ }
+
+ protected void assertArraysEquals(String message, Object expected, Object actual) {
+ if (expected instanceof byte[] && actual instanceof byte[]) {
+ assertArrayEquals(message, (byte[]) expected, (byte[]) actual);
+ } else if (expected instanceof Object[] && actual instanceof Object[]) {
+ assertArrayEquals(message, (Object[]) expected, (Object[]) actual);
+ } else if (expected instanceof char[] && actual instanceof char[]) {
+ assertArrayEquals(message, (char[]) expected, (char[]) actual);
+ } else if (expected instanceof short[] && actual instanceof short[]) {
+ assertArrayEquals(message, (short[]) expected, (short[]) actual);
+ } else if (expected instanceof int[] && actual instanceof int[]) {
+ assertArrayEquals(message, (int[]) expected, (int[]) actual);
+ } else if (expected instanceof long[] && actual instanceof long[]) {
+ assertArrayEquals(message, (long[]) expected, (long[]) actual);
+ } else if (expected instanceof float[] && actual instanceof float[]) {
+ assertArrayEquals(message, (float[]) expected, (float[]) actual, DELTA);
+ } else if (expected instanceof double[] && actual instanceof double[]) {
+ assertArrayEquals(message, (double[]) expected, (double[]) actual, DELTA);
+ } else {
+ fail(String.format("%s: Error comparing arrays of type '%s' and '%s'",
+ expected.getClass().getName(), (actual == null ? "null" : actual.getClass().getName())));
+ }
+ }
+}
[03/10] Make tests extend shared base class. Add additional tracking
in base class around memory usage per test.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java
index c508b21..b7f002e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java
@@ -25,6 +25,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -49,11 +50,11 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestSimpleSort {
+public class TestSimpleSort extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleSort.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void sortOneKeyAscending(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
@@ -63,14 +64,14 @@ public class TestSimpleSort {
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/sort/one_key_sort.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
+
int previousInt = Integer.MIN_VALUE;
int recordCount = 0;
@@ -80,20 +81,20 @@ public class TestSimpleSort {
batchCount++;
IntVector c1 = exec.getValueVectorById(new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class);
IntVector c2 = exec.getValueVectorById(new SchemaPath("green", ExpressionPosition.UNKNOWN), IntVector.class);
-
+
IntVector.Accessor a1 = c1.getAccessor();
IntVector.Accessor a2 = c2.getAccessor();
-
+
for(int i =0; i < c1.getAccessor().getValueCount(); i++){
recordCount++;
assert previousInt <= a1.get(i);
previousInt = a1.get(i);
assert previousInt == a2.get(i);
}
-
-
+
+
}
-
+
System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
if(context.getFailureCause() != null){
@@ -101,7 +102,7 @@ public class TestSimpleSort {
}
assertTrue(!context.isFailed());
}
-
+
@Test
public void sortTwoKeysOneAscendingOneDescending(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
@@ -111,17 +112,17 @@ public class TestSimpleSort {
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/sort/two_key_sort.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
+
int previousInt = Integer.MIN_VALUE;
long previousLong = Long.MAX_VALUE;
-
+
int recordCount = 0;
int batchCount = 0;
@@ -129,28 +130,28 @@ public class TestSimpleSort {
batchCount++;
IntVector c1 = exec.getValueVectorById(new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class);
BigIntVector c2 = exec.getValueVectorById(new SchemaPath("alt", ExpressionPosition.UNKNOWN), BigIntVector.class);
-
+
IntVector.Accessor a1 = c1.getAccessor();
BigIntVector.Accessor a2 = c2.getAccessor();
-
+
for(int i =0; i < c1.getAccessor().getValueCount(); i++){
recordCount++;
assert previousInt <= a1.get(i);
-
+
if(previousInt != a1.get(i)){
previousLong = Long.MAX_VALUE;
previousInt = a1.get(i);
}
-
+
assert previousLong >= a2.get(i);
-
+
//System.out.println(previousInt + "\t" + a2.get(i));
-
+
}
-
-
+
+
}
-
+
System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
if(context.getFailureCause() != null){
@@ -158,7 +159,7 @@ public class TestSimpleSort {
}
assertTrue(!context.isFailed());
}
-
+
@AfterClass
public static void tearDown() throws Exception{
// pause to get logger to catch up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/svremover/TestSVRemover.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/svremover/TestSVRemover.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/svremover/TestSVRemover.java
index fa04654..e45c938 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/svremover/TestSVRemover.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/svremover/TestSVRemover.java
@@ -24,6 +24,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -48,11 +49,11 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.codahale.metrics.MetricRegistry;
-public class TestSVRemover {
+public class TestSVRemover extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSVRemover.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void testSelectionVectorRemoval(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{
// System.out.println(System.getProperty("java.class.path"));
@@ -63,8 +64,8 @@ public class TestSVRemover {
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/remover/test1.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
@@ -77,14 +78,14 @@ public class TestSVRemover {
assertEquals(count, a.getValueCount());
}
}
-
+
if(context.getFailureCause() != null){
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
-
+
@AfterClass
public static void tearDown() throws Exception{
// pause to get logger to catch up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java
index b7b148c..f115c44 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java
@@ -23,6 +23,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
@@ -53,7 +54,7 @@ import com.codahale.metrics.MetricRegistry;
* multiple record batches and when there is a selection vector present in the
* incoming container of the trace operator.
*/
-public class TestTraceMultiRecordBatch {
+public class TestTraceMultiRecordBatch extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
index 910d782..f42efd4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java
@@ -23,6 +23,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.cache.VectorAccessibleSerializable;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
@@ -67,7 +68,7 @@ import com.codahale.metrics.MetricRegistry;
* the record that is dumped (Integer.MIN_VALUE) so we compare it with this
* known value.
*/
-public class TestTraceOutputDump {
+public class TestTraceOutputDump extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class);
DrillConfig c = DrillConfig.create();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
index a57b41f..fc88f2a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java
@@ -26,6 +26,7 @@ import mockit.NonStrictExpectations;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
@@ -47,42 +48,42 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-public class TestSimpleUnion {
+public class TestSimpleUnion extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleUnion.class);
DrillConfig c = DrillConfig.create();
-
-
+
+
@Test
public void testUnion(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable{
-
+
new NonStrictExpectations(){{
bitContext.getMetrics(); result = new MetricRegistry();
bitContext.getAllocator(); result = new TopLevelAllocator();
bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
}};
-
-
+
+
PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/union/test1.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
-
+
int[] counts = new int[]{100,50};
int i=0;
while(exec.next()){
System.out.println("iteration count:" + exec.getRecordCount());
assertEquals(counts[i++], exec.getRecordCount());
}
-
+
if(context.getFailureCause() != null){
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
-
+
}
-
+
@After
public void tearDown() throws Exception{
// pause to get logger to catch up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
index e5cd508..79bdbae 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/PopUnitTestBase.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.exception.FragmentSetupException;
import org.apache.drill.exec.physical.PhysicalPlan;
import org.apache.drill.exec.physical.base.PhysicalOperator;
@@ -37,9 +38,9 @@ import org.junit.rules.Timeout;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
-public abstract class PopUnitTestBase {
+public abstract class PopUnitTestBase extends ExecTest{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PopUnitTestBase.class);
-
+
// Determine if we are in Eclipse Debug mode.
static final boolean IS_DEBUG = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
protected static DrillConfig CONFIG;
@@ -52,7 +53,7 @@ public abstract class PopUnitTestBase {
CONFIG = DrillConfig.create();
}
-
+
public static int getFragmentCount(Fragment b) {
int i = 1;
for (ExchangeFragmentPair p : b) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestInjectionValue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestInjectionValue.java b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestInjectionValue.java
index f7c0d06..43fce83 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestInjectionValue.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/pop/TestInjectionValue.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.physical.PhysicalPlan;
import org.apache.drill.exec.physical.base.PhysicalOperator;
import org.apache.drill.exec.physical.config.Screen;
@@ -34,23 +35,23 @@ import org.junit.Test;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
-public class TestInjectionValue {
+public class TestInjectionValue extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestInjectionValue.class);
-
+
static DrillConfig config;
-
+
@BeforeClass
public static void setup(){
config = DrillConfig.create();
}
-
+
@Test
public void testInjected() throws Exception{
PhysicalPlanReader r = new PhysicalPlanReader(config, config.getMapper(), DrillbitEndpoint.getDefaultInstance());
PhysicalPlan p = r.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_screen.json"), Charsets.UTF_8));
-
+
List<PhysicalOperator> o = p.getSortedOperators(false);
-
+
PhysicalOperator op = o.iterator().next();
assertEquals(Screen.class, op.getClass());
Screen s = (Screen) op;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
index 1cc77f9..78fb1c1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java
@@ -20,7 +20,6 @@ package org.apache.drill.exec.record;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-
import mockit.Injectable;
import mockit.NonStrictExpectations;
@@ -38,6 +37,7 @@ import org.apache.drill.common.types.TypeProtos.DataMode;
import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.expr.ExpressionTreeMaterializer;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
@@ -48,7 +48,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Range;
-public class ExpressionTreeMaterializerTest {
+public class ExpressionTreeMaterializerTest extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTreeMaterializerTest.class);
@@ -58,7 +58,7 @@ public class ExpressionTreeMaterializerTest {
DrillConfig c = DrillConfig.create();
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
-
+
private MaterializedField getField(int fieldId, String name, MajorType type) {
return new MaterializedField(FieldDef.newBuilder().setMajorType(type).addName(NamePart.newBuilder().setName(name))
.build());
@@ -202,7 +202,7 @@ public class ExpressionTreeMaterializerTest {
}
};
-
+
LogicalExpression functionCallExpr = new FunctionCall("testFunc",
ImmutableList.of((LogicalExpression) new FieldReference("test", ExpressionPosition.UNKNOWN) ),
ExpressionPosition.UNKNOWN);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
index 6251c7f..5c5d566 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestLoad.java
@@ -27,6 +27,7 @@ import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.record.MaterializedField;
@@ -42,7 +43,8 @@ import org.junit.Test;
import com.google.common.collect.Lists;
-public class TestLoad {
+public class TestLoad extends ExecTest {
+
@Test
public void testLoadValueVector() throws Exception {
BufferAllocator allocator = new TopLevelAllocator();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
index d04e4b3..d79735b 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/vector/TestValueVector.java
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
import org.apache.drill.common.types.TypeProtos.DataMode;
import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.proto.SchemaDefProtos.FieldDef;
@@ -35,7 +36,7 @@ import org.apache.drill.exec.vector.NullableVarCharVector;
import org.apache.drill.exec.vector.UInt4Vector;
import org.junit.Test;
-public class TestValueVector {
+public class TestValueVector extends ExecTest {
TopLevelAllocator allocator = new TopLevelAllocator();
@@ -108,7 +109,7 @@ public class TestValueVector {
boolean b = false;
try {
v.getAccessor().get(3);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
@@ -154,30 +155,30 @@ public class TestValueVector {
boolean b = false;
try {
v.getAccessor().get(3);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
assert false;
}
- }
+ }
}
-
+
v.allocateNew(2048);
{
boolean b = false;
try {
v.getAccessor().get(0);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
assert false;
}
- }
+ }
}
-
+
m.set(0, 100);
m.set(1, 101);
m.set(100, 102);
@@ -190,18 +191,18 @@ public class TestValueVector {
assertEquals(104, v.getAccessor().get(1023));
// Ensure null values throw
-
+
{
boolean b = false;
try {
v.getAccessor().get(3);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
assert false;
}
- }
+ }
}
}
@@ -241,27 +242,27 @@ public class TestValueVector {
boolean b = false;
try {
v.getAccessor().get(3);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
assert false;
}
- }
+ }
}
-
+
v.allocateNew(2048);
{
boolean b = false;
try {
v.getAccessor().get(0);
- } catch(AssertionError e) {
+ } catch(AssertionError e) {
b = true;
}finally{
if(!b){
assert false;
}
- }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestBitRpc.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestBitRpc.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestBitRpc.java
index cb81175..74f5ba9 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestBitRpc.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestBitRpc.java
@@ -31,6 +31,7 @@ import org.apache.drill.common.expression.ExpressionPosition;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.proto.BitData.FragmentRecordBatch;
@@ -61,7 +62,7 @@ import org.junit.Test;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
-public class TestBitRpc {
+public class TestBitRpc extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestBitRpc.class);
@Test
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java
index 67b11cb..58a36a8 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java
@@ -24,6 +24,7 @@ import junit.framework.Assert;
import mockit.Injectable;
import mockit.NonStrictExpectations;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.physical.EndpointAffinity;
import org.apache.drill.exec.proto.CoordinationProtos;
import org.apache.drill.exec.server.DrillbitContext;
@@ -46,7 +47,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-public class TestAffinityCalculator {
+public class TestAffinityCalculator extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestAffinityCalculator.class);
String port = "1234";
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
index f61f4ee..d7e74cb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
@@ -22,7 +22,7 @@ import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.tools.Frameworks;
import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.exec.cache.HazelCache;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.cache.LocalCache;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.server.DrillbitContext;
@@ -30,7 +30,7 @@ import org.junit.Test;
import com.codahale.metrics.MetricRegistry;
-public class TestOrphanSchema {
+public class TestOrphanSchema extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestOrphanSchema.class);
@@ -52,7 +52,7 @@ public class TestOrphanSchema {
};
bitContext.getCache().run();
-
+
StoragePluginRegistry r = new StoragePluginRegistry(bitContext);
SchemaPlus plus = Frameworks.createRootSchema();
r.init();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestOrphanSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestOrphanSchema.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestOrphanSchema.java
index d4755fa..0e06af1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestOrphanSchema.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestOrphanSchema.java
@@ -26,6 +26,7 @@ import java.util.List;
import net.hydromatic.optiq.SchemaPlus;
import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -46,7 +47,7 @@ import org.junit.Test;
* Using an orphan schema, create and display the various information schema tables.
* An "orphan schema" is a stand alone schema which is not (yet?) connected to Optiq.
*/
-public class TestOrphanSchema {
+public class TestOrphanSchema extends ExecTest {
static SchemaPlus root;
@BeforeClass
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestTableProvider.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestTableProvider.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestTableProvider.java
index 0cc0b71..e1ed53a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestTableProvider.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/TestTableProvider.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -39,7 +40,7 @@ import org.junit.Test;
/**
* Using a test table with two columns, create data and verify the values are in the record batch.
*/
-public class TestTableProvider {
+public class TestTableProvider extends ExecTest {
@Test
public void zeroRead() {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JSONRecordReaderTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JSONRecordReaderTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JSONRecordReaderTest.java
index 9f54349..c3e7491 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JSONRecordReaderTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JSONRecordReaderTest.java
@@ -38,6 +38,7 @@ import org.apache.drill.common.expression.FieldReference;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.memory.TopLevelAllocator;
import org.apache.drill.exec.ops.FragmentContext;
@@ -55,7 +56,7 @@ import org.junit.Test;
import com.google.common.collect.Lists;
-public class JSONRecordReaderTest {
+public class JSONRecordReaderTest extends ExecTest {
private static final Charset UTF_8 = Charset.forName("UTF-8");
private String getResource(String resourceName) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetPhysicalPlan.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetPhysicalPlan.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetPhysicalPlan.java
index 4d9b606..a885ede 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetPhysicalPlan.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetPhysicalPlan.java
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.proto.UserBitShared.QueryId;
import org.apache.drill.exec.proto.UserProtos;
@@ -43,7 +44,7 @@ import com.google.common.base.Charsets;
import com.google.common.base.Stopwatch;
import com.google.common.io.Resources;
-public class TestParquetPhysicalPlan {
+public class TestParquetPhysicalPlan extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestParquetPhysicalPlan.class);
public String fileName = "parquet/parquet_scan_filter_union_screen_physical.json";
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/exec/java-exec/src/test/java/org/apache/drill/exec/work/batch/TestSpoolingBuffer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/work/batch/TestSpoolingBuffer.java b/exec/java-exec/src/test/java/org/apache/drill/exec/work/batch/TestSpoolingBuffer.java
index d8c280a..e2fc3f7 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/work/batch/TestSpoolingBuffer.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/work/batch/TestSpoolingBuffer.java
@@ -20,8 +20,10 @@ package org.apache.drill.exec.work.batch;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;
+
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.proto.UserProtos;
import org.apache.drill.exec.rpc.user.QueryResultBatch;
@@ -34,7 +36,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
-public class TestSpoolingBuffer {
+public class TestSpoolingBuffer extends ExecTest {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSpoolingBuffer.class);
@Test
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/pom.xml
----------------------------------------------------------------------
diff --git a/sqlparser/pom.xml b/sqlparser/pom.xml
index 8266dcb..931fc7d 100644
--- a/sqlparser/pom.xml
+++ b/sqlparser/pom.xml
@@ -35,7 +35,13 @@
<artifactId>drill-java-exec</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.drill</groupId>
+ <artifactId>drill-common</artifactId>
+ <classifier>tests</classifier>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-java-exec</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/src/test/java/org/apache/drill/jdbc/JdbcTest.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/JdbcTest.java b/sqlparser/src/test/java/org/apache/drill/jdbc/JdbcTest.java
new file mode 100644
index 0000000..3f44ed8
--- /dev/null
+++ b/sqlparser/src/test/java/org/apache/drill/jdbc/JdbcTest.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.jdbc;
+
+import org.apache.drill.exec.ExecTest;
+
+public class JdbcTest extends ExecTest{
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JdbcTest.class);
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
new file mode 100644
index 0000000..0e9f8a0
--- /dev/null
+++ b/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java
@@ -0,0 +1,521 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.jdbc.test;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.apache.drill.common.logical.LogicalPlan;
+import org.apache.drill.common.logical.PlanProperties;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.common.logical.data.Filter;
+import org.apache.drill.common.logical.data.Join;
+import org.apache.drill.common.logical.data.Limit;
+import org.apache.drill.common.logical.data.LogicalOperator;
+import org.apache.drill.common.logical.data.Order;
+import org.apache.drill.common.logical.data.Project;
+import org.apache.drill.common.logical.data.Scan;
+import org.apache.drill.common.logical.data.Store;
+import org.apache.drill.common.logical.data.Union;
+import org.apache.drill.jdbc.JdbcTest;
+import org.apache.drill.jdbc.test.JdbcAssert.TestDataConnection;
+import org.eigenbase.rel.JoinRelType;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.io.Resources;
+
+/** Unit tests for Drill's JDBC driver. */
+
+
+@Ignore // ignore for now.
+public class JdbcDataTest extends JdbcTest{
+ private static String MODEL;
+ private static String EXPECTED;
+
+
+ @BeforeClass
+ public static void setupFixtures() throws IOException {
+ MODEL = Resources.toString(Resources.getResource("test-models.json"), Charsets.UTF_8);
+ EXPECTED = Resources.toString(Resources.getResource("donuts-output-data.txt"), Charsets.UTF_8);
+ }
+
+ /**
+ * Command-line utility to execute a logical plan.
+ *
+ * <p>
+ * The forwarding method ensures that the IDE calls this method with the right classpath.
+ * </p>
+ */
+ public static void main(String[] args) throws Exception {
+ }
+
+ /** Load driver. */
+ @Test
+ public void testLoadDriver() throws ClassNotFoundException {
+ Class.forName("org.apache.drill.jdbc.Driver");
+ }
+
+ /** Load driver and make a connection. */
+ @Test
+ public void testConnect() throws Exception {
+ Class.forName("org.apache.drill.jdbc.Driver");
+ final Connection connection = DriverManager.getConnection("jdbc:drill:zk=local");
+ connection.close();
+ }
+
+ /** Load driver, make a connection, prepare a statement. */
+ @Test
+ public void testPrepare() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ final Statement statement = connection.prepareStatement("select * from donuts");
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
+
+ /** Simple query against JSON. */
+ @Test
+ public void testSelectJson() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts").returns(EXPECTED);
+ }
+
+ /** Simple query against EMP table in HR database. */
+ @Test
+ public void testSelectEmployees() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from employees")
+ .returns(
+ "_MAP={deptId=31, lastName=Rafferty}\n" + "_MAP={deptId=33, lastName=Jones}\n"
+ + "_MAP={deptId=33, lastName=Steinberg}\n" + "_MAP={deptId=34, lastName=Robinson}\n"
+ + "_MAP={deptId=34, lastName=Smith}\n" + "_MAP={lastName=John}\n");
+ }
+
+ /** Simple query against EMP table in HR database. */
+ @Test
+ public void testSelectEmpView() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp")
+ .returns(
+ "DEPTID=31; LASTNAME=Rafferty\n" + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n"
+ + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" + "DEPTID=null; LASTNAME=John\n");
+ }
+
+ /** Simple query against EMP table in HR database. */
+ @Test
+ public void testSelectDept() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from departments")
+ .returns(
+ "_MAP={deptId=31, name=Sales}\n" + "_MAP={deptId=33, name=Engineering}\n"
+ + "_MAP={deptId=34, name=Clerical}\n" + "_MAP={deptId=35, name=Marketing}\n");
+ }
+
+ /** Query with project list. No field references yet. */
+ @Test
+ public void testProjectConstant() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select 1 + 3 as c from donuts")
+ .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n");
+ }
+
+ /** Query that projects an element from the map. */
+ @Test
+ public void testProject() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select _MAP['ppu'] as ppu from donuts")
+ .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n");
+ }
+
+ /** Same logic as {@link #testProject()}, but using a subquery. */
+ @Test
+ public void testProjectOnSubquery() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select d['ppu'] as ppu from (\n" + " select _MAP as d from donuts)")
+ .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n");
+ }
+
+ /** Checks the logical plan. */
+ @Test
+ public void testProjectPlan() throws Exception {
+ LogicalPlan plan = JdbcAssert
+ .withModel(MODEL, "DONUTS")
+ .sql("select _MAP['ppu'] as ppu from donuts")
+ .logicalPlan();
+
+ PlanProperties planProperties = plan.getProperties();
+ Assert.assertEquals("optiq", planProperties.generator.type);
+ Assert.assertEquals("na", planProperties.generator.info);
+ Assert.assertEquals(1, planProperties.version);
+ Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
+ Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
+ StoragePluginConfig config = seConfigs.get("donuts-json");
+// Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
+ config = seConfigs.get("queue");
+// Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
+ Scan scan = findOnlyOperator(plan, Scan.class);
+ Assert.assertEquals("donuts-json", scan.getStorageEngine());
+ Project project = findOnlyOperator(plan, Project.class);
+ Assert.assertEquals(1, project.getSelections().length);
+ Assert.assertEquals(Scan.class, project.getInput().getClass());
+ Store store = findOnlyOperator(plan, Store.class);
+ Assert.assertEquals("queue", store.getStorageEngine());
+ Assert.assertEquals("output sink", store.getMemo());
+ Assert.assertEquals(Project.class, store.getInput().getClass());
+ }
+
+ /**
+ * Query with subquery, filter, and projection of one real and one nonexistent field from a map field.
+ */
+ @Test
+ public void testProjectFilterSubquery() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "DONUTS")
+ .sql(
+ "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP as d from donuts)\n"
+ + "where cast(d['ppu'] as double) > 0.6")
+ .returns("NAME=Raised; XX=null\n" + "NAME=Filled; XX=null\n" + "NAME=Apple Fritter; XX=null\n");
+ }
+
+ private static <T extends LogicalOperator> Iterable<T> findOperator(LogicalPlan plan, final Class<T> operatorClazz) {
+ return (Iterable<T>) Iterables.filter(plan.getSortedOperators(), new Predicate<LogicalOperator>() {
+ @Override
+ public boolean apply(LogicalOperator input) {
+ return input.getClass().equals(operatorClazz);
+ }
+ });
+ }
+
+ private static <T extends LogicalOperator> T findOnlyOperator(LogicalPlan plan, final Class<T> operatorClazz) {
+ return Iterables.getOnlyElement(findOperator(plan, operatorClazz));
+ }
+
+ @Test
+ public void testProjectFilterSubqueryPlan() throws Exception {
+ LogicalPlan plan = JdbcAssert
+ .withModel(MODEL, "DONUTS")
+ .sql(
+ "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP['donuts'] as d from donuts)\n"
+ + "where cast(d['ppu'] as double) > 0.6")
+ .logicalPlan();
+ PlanProperties planProperties = plan.getProperties();
+ Assert.assertEquals("optiq", planProperties.generator.type);
+ Assert.assertEquals("na", planProperties.generator.info);
+ Assert.assertEquals(1, planProperties.version);
+ Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
+ Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
+ StoragePluginConfig config = seConfigs.get("donuts-json");
+// Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
+ config = seConfigs.get("queue");
+// Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
+ Scan scan = findOnlyOperator(plan, Scan.class);
+ Assert.assertEquals("donuts-json", scan.getStorageEngine());
+ Filter filter = findOnlyOperator(plan, Filter.class);
+ Assert.assertTrue(filter.getInput() instanceof Scan);
+ Project[] projects = Iterables.toArray(findOperator(plan, Project.class), Project.class);
+ Assert.assertEquals(2, projects.length);
+ Assert.assertEquals(1, projects[0].getSelections().length);
+ Assert.assertEquals(Filter.class, projects[0].getInput().getClass());
+ Assert.assertEquals(2, projects[1].getSelections().length);
+ Assert.assertEquals(Project.class, projects[1].getInput().getClass());
+ Store store = findOnlyOperator(plan, Store.class);
+ Assert.assertEquals("queue", store.getStorageEngine());
+ Assert.assertEquals("output sink", store.getMemo());
+ Assert.assertEquals(Project.class, store.getInput().getClass());
+ }
+
+ /** Query that projects one field. (Disabled; uses sugared syntax.) */
+ @Test @Ignore
+ public void testProjectNestedFieldSugared() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select donuts.ppu from donuts")
+ .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n");
+ }
+
+ /** Query with filter. No field references yet. */
+ @Test
+ public void testFilterConstantFalse() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 > 4").returns("");
+ }
+
+ @Test
+ public void testFilterConstant() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 < 4").returns(EXPECTED);
+ }
+
+
+ @Ignore
+ @Test
+ public void testValues() throws Exception {
+ JdbcAssert.withModel(MODEL, "DONUTS").sql("values (1)").returns("EXPR$0=1\n");
+
+ // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed
+ // .planContains("store");
+ }
+
+// @Test
+// public void testDistinct() throws Exception {
+// JdbcAssert.withModel(MODEL, "HR").sql("select distinct deptId from emp")
+// .returnsUnordered("DEPTID=null", "DEPTID=31", "DEPTID=34", "DEPTID=33")
+// .planContains(CollapsingAggregate.class);
+// }
+//
+// @Test
+// public void testCountNoGroupBy() throws Exception {
+// // 5 out of 6 employees have a not-null deptId
+// JdbcAssert.withModel(MODEL, "HR").sql("select count(deptId) as cd, count(*) as c from emp").returns("CD=5; C=6\n")
+// .planContains(CollapsingAggregate.class);
+// }
+//
+// @Test
+// public void testDistinctCountNoGroupBy() throws Exception {
+// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp").returns("C=3\n")
+// .planContains(CollapsingAggregate.class);
+// }
+//
+// @Test
+// public void testDistinctCountGroupByEmpty() throws Exception {
+// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n")
+// .planContains(CollapsingAggregate.class);
+// }
+//
+// @Test
+// public void testCountNull() throws Exception {
+// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n")
+// .planContains(CollapsingAggregate.class);
+// }
+//
+// @Test
+// public void testCount() throws Exception {
+// JdbcAssert.withModel(MODEL, "HR").sql("select deptId, count(*) as c from emp group by deptId")
+// .returnsUnordered("DEPTID=31; C=1", "DEPTID=33; C=2", "DEPTID=34; C=2", "DEPTID=null; C=1")
+// .planContains(CollapsingAggregate.class); // make sure using drill
+// }
+
+ @Test
+ public void testJoin() throws Exception {
+ Join join = JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp join dept on emp.deptId = dept.deptId")
+ .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
+ "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
+ "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
+ "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
+ "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical").planContains(Join.class);
+ Assert.assertEquals(JoinRelType.INNER, join.getJoinType());
+ }
+
+ @Test
+ public void testLeftJoin() throws Exception {
+ Join join = JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp left join dept on emp.deptId = dept.deptId")
+ .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
+ "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
+ "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
+ "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
+ "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical",
+ "DEPTID=null; LASTNAME=John; DEPTID0=null; NAME=null").planContains(Join.class);
+ Assert.assertEquals(JoinRelType.LEFT, join.getJoinType());
+ }
+
+ /**
+ * Right join is tricky because Drill's "join" operator only supports "left", so we have to flip inputs.
+ */
+ @Test @Ignore
+ public void testRightJoin() throws Exception {
+ Join join = JdbcAssert.withModel(MODEL, "HR").sql("select * from emp right join dept on emp.deptId = dept.deptId")
+ .returnsUnordered("xx").planContains(Join.class);
+ Assert.assertEquals(JoinRelType.LEFT, join.getJoinType());
+ }
+
+ @Test
+ public void testFullJoin() throws Exception {
+ Join join = JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp full join dept on emp.deptId = dept.deptId")
+ .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
+ "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
+ "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
+ "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
+ "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical",
+ "DEPTID=null; LASTNAME=John; DEPTID0=null; NAME=null",
+ "DEPTID=null; LASTNAME=null; DEPTID0=35; NAME=Marketing").planContains(Join.class);
+ Assert.assertEquals(JoinRelType.FULL, join.getJoinType());
+ }
+
+ /**
+ * Join on subquery; also tests that if a field of the same name exists in both inputs, both fields make it through
+ * the join.
+ */
+ @Test
+ public void testJoinOnSubquery() throws Exception {
+ Join join = JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql(
+ "select * from (\n" + "select deptId, lastname, 'x' as name from emp) as e\n"
+ + " join dept on e.deptId = dept.deptId")
+ .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; NAME=x; DEPTID0=31; NAME0=Sales",
+ "DEPTID=33; LASTNAME=Jones; NAME=x; DEPTID0=33; NAME0=Engineering",
+ "DEPTID=33; LASTNAME=Steinberg; NAME=x; DEPTID0=33; NAME0=Engineering",
+ "DEPTID=34; LASTNAME=Robinson; NAME=x; DEPTID0=34; NAME0=Clerical",
+ "DEPTID=34; LASTNAME=Smith; NAME=x; DEPTID0=34; NAME0=Clerical").planContains(Join.class);
+ Assert.assertEquals(JoinRelType.INNER, join.getJoinType());
+ }
+
+ /** Tests that one of the FoodMart tables is present. */
+ @Test @Ignore
+ public void testFoodMart() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "FOODMART")
+ .sql("select * from product_class where cast(_map['product_class_id'] as integer) < 3")
+ .returnsUnordered(
+ "_MAP={product_category=Seafood, product_class_id=2, product_department=Seafood, product_family=Food, product_subcategory=Shellfish}",
+ "_MAP={product_category=Specialty, product_class_id=1, product_department=Produce, product_family=Food, product_subcategory=Nuts}");
+ }
+
+ @Test
+ public void testUnionAll() throws Exception {
+ Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union all\n" + "select deptId from emp")
+ .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null")
+ .planContains(Union.class);
+ Assert.assertFalse(union.isDistinct());
+ }
+
+ @Test
+ public void testUnion() throws Exception {
+ Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union\n" + "select deptId from emp")
+ .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null")
+ .planContains(Union.class);
+ Assert.assertTrue(union.isDistinct());
+ }
+
+ @Test
+ public void testOrderByDescNullsFirst() throws Exception {
+ // desc nulls last
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp order by deptId desc nulls first")
+ .returns(
+ "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n"
+ + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n")
+ .planContains(Order.class);
+ }
+
+ @Test
+ public void testOrderByDescNullsLast() throws Exception {
+ // desc nulls first
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp order by deptId desc nulls last")
+ .returns(
+ "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" + "DEPTID=33; LASTNAME=Jones\n"
+ + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n" + "DEPTID=null; LASTNAME=John\n")
+ .planContains(Order.class);
+ }
+
+ @Test @Ignore
+ public void testOrderByDesc() throws Exception {
+ // desc is implicitly "nulls first" (i.e. null sorted as +inf)
+ // Current behavior is to sort nulls last. This is wrong.
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp order by deptId desc")
+ .returns(
+ "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n"
+ + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n")
+ .planContains(Order.class);
+ }
+
+ @Test
+ public void testOrderBy() throws Exception {
+ // no sort order specified is implicitly "asc", and asc is "nulls last"
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select * from emp order by deptId")
+ .returns(
+ "DEPTID=31; LASTNAME=Rafferty\n"
+ + "DEPTID=33; LASTNAME=Jones\n"
+ + "DEPTID=33; LASTNAME=Steinberg\n"
+ + "DEPTID=34; LASTNAME=Robinson\n"
+ + "DEPTID=34; LASTNAME=Smith\n"
+ + "DEPTID=null; LASTNAME=John\n")
+ .planContains(Order.class);
+ }
+
+ @Test
+ public void testLimit() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select LASTNAME from emp limit 2")
+ .returns("LASTNAME=Rafferty\n" +
+ "LASTNAME=Jones")
+ .planContains(Limit.class);
+ }
+
+
+ @Test
+ public void testLimitOrderBy() throws Exception {
+ TestDataConnection tdc = JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select LASTNAME from emp order by LASTNAME limit 2")
+ .returns("LASTNAME=John\n" +
+ "LASTNAME=Jones");
+ tdc.planContains(Limit.class);
+ tdc.planContains(Order.class);
+
+ }
+
+ @Test
+ public void testOrderByWithOffset() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select LASTNAME from emp order by LASTNAME asc offset 3")
+ .returns("LASTNAME=Robinson\n" +
+ "LASTNAME=Smith\n" +
+ "LASTNAME=Steinberg")
+ .planContains(Limit.class);
+
+ }
+
+ @Test
+ public void testOrderByWithOffsetAndFetch() throws Exception {
+ JdbcAssert
+ .withModel(MODEL, "HR")
+ .sql("select LASTNAME from emp order by LASTNAME asc offset 3 fetch next 2 rows only")
+ .returns("LASTNAME=Robinson\n" +
+ "LASTNAME=Smith")
+ .planContains(Limit.class);
+ }
+}
+
+// End JdbcTest.java
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/16481951/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java
deleted file mode 100644
index 1e4edca..0000000
--- a/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java
+++ /dev/null
@@ -1,520 +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.drill.jdbc.test;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.Map;
-
-import org.apache.drill.common.logical.LogicalPlan;
-import org.apache.drill.common.logical.PlanProperties;
-import org.apache.drill.common.logical.StoragePluginConfig;
-import org.apache.drill.common.logical.data.Filter;
-import org.apache.drill.common.logical.data.Join;
-import org.apache.drill.common.logical.data.Limit;
-import org.apache.drill.common.logical.data.LogicalOperator;
-import org.apache.drill.common.logical.data.Order;
-import org.apache.drill.common.logical.data.Project;
-import org.apache.drill.common.logical.data.Scan;
-import org.apache.drill.common.logical.data.Store;
-import org.apache.drill.common.logical.data.Union;
-import org.apache.drill.jdbc.test.JdbcAssert.TestDataConnection;
-import org.eigenbase.rel.JoinRelType;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.io.Resources;
-
-/** Unit tests for Drill's JDBC driver. */
-
-
-@Ignore // ignore for now.
-public class JdbcTest {
- private static String MODEL;
- private static String EXPECTED;
-
-
- @BeforeClass
- public static void setupFixtures() throws IOException {
- MODEL = Resources.toString(Resources.getResource("test-models.json"), Charsets.UTF_8);
- EXPECTED = Resources.toString(Resources.getResource("donuts-output-data.txt"), Charsets.UTF_8);
- }
-
- /**
- * Command-line utility to execute a logical plan.
- *
- * <p>
- * The forwarding method ensures that the IDE calls this method with the right classpath.
- * </p>
- */
- public static void main(String[] args) throws Exception {
- }
-
- /** Load driver. */
- @Test
- public void testLoadDriver() throws ClassNotFoundException {
- Class.forName("org.apache.drill.jdbc.Driver");
- }
-
- /** Load driver and make a connection. */
- @Test
- public void testConnect() throws Exception {
- Class.forName("org.apache.drill.jdbc.Driver");
- final Connection connection = DriverManager.getConnection("jdbc:drill:zk=local");
- connection.close();
- }
-
- /** Load driver, make a connection, prepare a statement. */
- @Test
- public void testPrepare() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").withConnection(new Function<Connection, Void>() {
- public Void apply(Connection connection) {
- try {
- final Statement statement = connection.prepareStatement("select * from donuts");
- statement.close();
- return null;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
-
- /** Simple query against JSON. */
- @Test
- public void testSelectJson() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts").returns(EXPECTED);
- }
-
- /** Simple query against EMP table in HR database. */
- @Test
- public void testSelectEmployees() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from employees")
- .returns(
- "_MAP={deptId=31, lastName=Rafferty}\n" + "_MAP={deptId=33, lastName=Jones}\n"
- + "_MAP={deptId=33, lastName=Steinberg}\n" + "_MAP={deptId=34, lastName=Robinson}\n"
- + "_MAP={deptId=34, lastName=Smith}\n" + "_MAP={lastName=John}\n");
- }
-
- /** Simple query against EMP table in HR database. */
- @Test
- public void testSelectEmpView() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp")
- .returns(
- "DEPTID=31; LASTNAME=Rafferty\n" + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n"
- + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" + "DEPTID=null; LASTNAME=John\n");
- }
-
- /** Simple query against EMP table in HR database. */
- @Test
- public void testSelectDept() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from departments")
- .returns(
- "_MAP={deptId=31, name=Sales}\n" + "_MAP={deptId=33, name=Engineering}\n"
- + "_MAP={deptId=34, name=Clerical}\n" + "_MAP={deptId=35, name=Marketing}\n");
- }
-
- /** Query with project list. No field references yet. */
- @Test
- public void testProjectConstant() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select 1 + 3 as c from donuts")
- .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n");
- }
-
- /** Query that projects an element from the map. */
- @Test
- public void testProject() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select _MAP['ppu'] as ppu from donuts")
- .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n");
- }
-
- /** Same logic as {@link #testProject()}, but using a subquery. */
- @Test
- public void testProjectOnSubquery() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select d['ppu'] as ppu from (\n" + " select _MAP as d from donuts)")
- .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n");
- }
-
- /** Checks the logical plan. */
- @Test
- public void testProjectPlan() throws Exception {
- LogicalPlan plan = JdbcAssert
- .withModel(MODEL, "DONUTS")
- .sql("select _MAP['ppu'] as ppu from donuts")
- .logicalPlan();
-
- PlanProperties planProperties = plan.getProperties();
- Assert.assertEquals("optiq", planProperties.generator.type);
- Assert.assertEquals("na", planProperties.generator.info);
- Assert.assertEquals(1, planProperties.version);
- Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
- Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
- StoragePluginConfig config = seConfigs.get("donuts-json");
-// Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
- config = seConfigs.get("queue");
-// Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
- Scan scan = findOnlyOperator(plan, Scan.class);
- Assert.assertEquals("donuts-json", scan.getStorageEngine());
- Project project = findOnlyOperator(plan, Project.class);
- Assert.assertEquals(1, project.getSelections().length);
- Assert.assertEquals(Scan.class, project.getInput().getClass());
- Store store = findOnlyOperator(plan, Store.class);
- Assert.assertEquals("queue", store.getStorageEngine());
- Assert.assertEquals("output sink", store.getMemo());
- Assert.assertEquals(Project.class, store.getInput().getClass());
- }
-
- /**
- * Query with subquery, filter, and projection of one real and one nonexistent field from a map field.
- */
- @Test
- public void testProjectFilterSubquery() throws Exception {
- JdbcAssert
- .withModel(MODEL, "DONUTS")
- .sql(
- "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP as d from donuts)\n"
- + "where cast(d['ppu'] as double) > 0.6")
- .returns("NAME=Raised; XX=null\n" + "NAME=Filled; XX=null\n" + "NAME=Apple Fritter; XX=null\n");
- }
-
- private static <T extends LogicalOperator> Iterable<T> findOperator(LogicalPlan plan, final Class<T> operatorClazz) {
- return (Iterable<T>) Iterables.filter(plan.getSortedOperators(), new Predicate<LogicalOperator>() {
- @Override
- public boolean apply(LogicalOperator input) {
- return input.getClass().equals(operatorClazz);
- }
- });
- }
-
- private static <T extends LogicalOperator> T findOnlyOperator(LogicalPlan plan, final Class<T> operatorClazz) {
- return Iterables.getOnlyElement(findOperator(plan, operatorClazz));
- }
-
- @Test
- public void testProjectFilterSubqueryPlan() throws Exception {
- LogicalPlan plan = JdbcAssert
- .withModel(MODEL, "DONUTS")
- .sql(
- "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP['donuts'] as d from donuts)\n"
- + "where cast(d['ppu'] as double) > 0.6")
- .logicalPlan();
- PlanProperties planProperties = plan.getProperties();
- Assert.assertEquals("optiq", planProperties.generator.type);
- Assert.assertEquals("na", planProperties.generator.info);
- Assert.assertEquals(1, planProperties.version);
- Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
- Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
- StoragePluginConfig config = seConfigs.get("donuts-json");
-// Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
- config = seConfigs.get("queue");
-// Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
- Scan scan = findOnlyOperator(plan, Scan.class);
- Assert.assertEquals("donuts-json", scan.getStorageEngine());
- Filter filter = findOnlyOperator(plan, Filter.class);
- Assert.assertTrue(filter.getInput() instanceof Scan);
- Project[] projects = Iterables.toArray(findOperator(plan, Project.class), Project.class);
- Assert.assertEquals(2, projects.length);
- Assert.assertEquals(1, projects[0].getSelections().length);
- Assert.assertEquals(Filter.class, projects[0].getInput().getClass());
- Assert.assertEquals(2, projects[1].getSelections().length);
- Assert.assertEquals(Project.class, projects[1].getInput().getClass());
- Store store = findOnlyOperator(plan, Store.class);
- Assert.assertEquals("queue", store.getStorageEngine());
- Assert.assertEquals("output sink", store.getMemo());
- Assert.assertEquals(Project.class, store.getInput().getClass());
- }
-
- /** Query that projects one field. (Disabled; uses sugared syntax.) */
- @Test @Ignore
- public void testProjectNestedFieldSugared() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select donuts.ppu from donuts")
- .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n");
- }
-
- /** Query with filter. No field references yet. */
- @Test
- public void testFilterConstantFalse() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 > 4").returns("");
- }
-
- @Test
- public void testFilterConstant() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 < 4").returns(EXPECTED);
- }
-
-
- @Ignore
- @Test
- public void testValues() throws Exception {
- JdbcAssert.withModel(MODEL, "DONUTS").sql("values (1)").returns("EXPR$0=1\n");
-
- // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed
- // .planContains("store");
- }
-
-// @Test
-// public void testDistinct() throws Exception {
-// JdbcAssert.withModel(MODEL, "HR").sql("select distinct deptId from emp")
-// .returnsUnordered("DEPTID=null", "DEPTID=31", "DEPTID=34", "DEPTID=33")
-// .planContains(CollapsingAggregate.class);
-// }
-//
-// @Test
-// public void testCountNoGroupBy() throws Exception {
-// // 5 out of 6 employees have a not-null deptId
-// JdbcAssert.withModel(MODEL, "HR").sql("select count(deptId) as cd, count(*) as c from emp").returns("CD=5; C=6\n")
-// .planContains(CollapsingAggregate.class);
-// }
-//
-// @Test
-// public void testDistinctCountNoGroupBy() throws Exception {
-// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp").returns("C=3\n")
-// .planContains(CollapsingAggregate.class);
-// }
-//
-// @Test
-// public void testDistinctCountGroupByEmpty() throws Exception {
-// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n")
-// .planContains(CollapsingAggregate.class);
-// }
-//
-// @Test
-// public void testCountNull() throws Exception {
-// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n")
-// .planContains(CollapsingAggregate.class);
-// }
-//
-// @Test
-// public void testCount() throws Exception {
-// JdbcAssert.withModel(MODEL, "HR").sql("select deptId, count(*) as c from emp group by deptId")
-// .returnsUnordered("DEPTID=31; C=1", "DEPTID=33; C=2", "DEPTID=34; C=2", "DEPTID=null; C=1")
-// .planContains(CollapsingAggregate.class); // make sure using drill
-// }
-
- @Test
- public void testJoin() throws Exception {
- Join join = JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp join dept on emp.deptId = dept.deptId")
- .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
- "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
- "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
- "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
- "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical").planContains(Join.class);
- Assert.assertEquals(JoinRelType.INNER, join.getJoinType());
- }
-
- @Test
- public void testLeftJoin() throws Exception {
- Join join = JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp left join dept on emp.deptId = dept.deptId")
- .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
- "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
- "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
- "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
- "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical",
- "DEPTID=null; LASTNAME=John; DEPTID0=null; NAME=null").planContains(Join.class);
- Assert.assertEquals(JoinRelType.LEFT, join.getJoinType());
- }
-
- /**
- * Right join is tricky because Drill's "join" operator only supports "left", so we have to flip inputs.
- */
- @Test @Ignore
- public void testRightJoin() throws Exception {
- Join join = JdbcAssert.withModel(MODEL, "HR").sql("select * from emp right join dept on emp.deptId = dept.deptId")
- .returnsUnordered("xx").planContains(Join.class);
- Assert.assertEquals(JoinRelType.LEFT, join.getJoinType());
- }
-
- @Test
- public void testFullJoin() throws Exception {
- Join join = JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp full join dept on emp.deptId = dept.deptId")
- .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales",
- "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering",
- "DEPTID=33; LASTNAME=Steinberg; DEPTID0=33; NAME=Engineering",
- "DEPTID=34; LASTNAME=Robinson; DEPTID0=34; NAME=Clerical",
- "DEPTID=34; LASTNAME=Smith; DEPTID0=34; NAME=Clerical",
- "DEPTID=null; LASTNAME=John; DEPTID0=null; NAME=null",
- "DEPTID=null; LASTNAME=null; DEPTID0=35; NAME=Marketing").planContains(Join.class);
- Assert.assertEquals(JoinRelType.FULL, join.getJoinType());
- }
-
- /**
- * Join on subquery; also tests that if a field of the same name exists in both inputs, both fields make it through
- * the join.
- */
- @Test
- public void testJoinOnSubquery() throws Exception {
- Join join = JdbcAssert
- .withModel(MODEL, "HR")
- .sql(
- "select * from (\n" + "select deptId, lastname, 'x' as name from emp) as e\n"
- + " join dept on e.deptId = dept.deptId")
- .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; NAME=x; DEPTID0=31; NAME0=Sales",
- "DEPTID=33; LASTNAME=Jones; NAME=x; DEPTID0=33; NAME0=Engineering",
- "DEPTID=33; LASTNAME=Steinberg; NAME=x; DEPTID0=33; NAME0=Engineering",
- "DEPTID=34; LASTNAME=Robinson; NAME=x; DEPTID0=34; NAME0=Clerical",
- "DEPTID=34; LASTNAME=Smith; NAME=x; DEPTID0=34; NAME0=Clerical").planContains(Join.class);
- Assert.assertEquals(JoinRelType.INNER, join.getJoinType());
- }
-
- /** Tests that one of the FoodMart tables is present. */
- @Test @Ignore
- public void testFoodMart() throws Exception {
- JdbcAssert
- .withModel(MODEL, "FOODMART")
- .sql("select * from product_class where cast(_map['product_class_id'] as integer) < 3")
- .returnsUnordered(
- "_MAP={product_category=Seafood, product_class_id=2, product_department=Seafood, product_family=Food, product_subcategory=Shellfish}",
- "_MAP={product_category=Specialty, product_class_id=1, product_department=Produce, product_family=Food, product_subcategory=Nuts}");
- }
-
- @Test
- public void testUnionAll() throws Exception {
- Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union all\n" + "select deptId from emp")
- .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null")
- .planContains(Union.class);
- Assert.assertFalse(union.isDistinct());
- }
-
- @Test
- public void testUnion() throws Exception {
- Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union\n" + "select deptId from emp")
- .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null")
- .planContains(Union.class);
- Assert.assertTrue(union.isDistinct());
- }
-
- @Test
- public void testOrderByDescNullsFirst() throws Exception {
- // desc nulls last
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp order by deptId desc nulls first")
- .returns(
- "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n"
- + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n")
- .planContains(Order.class);
- }
-
- @Test
- public void testOrderByDescNullsLast() throws Exception {
- // desc nulls first
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp order by deptId desc nulls last")
- .returns(
- "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" + "DEPTID=33; LASTNAME=Jones\n"
- + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n" + "DEPTID=null; LASTNAME=John\n")
- .planContains(Order.class);
- }
-
- @Test @Ignore
- public void testOrderByDesc() throws Exception {
- // desc is implicitly "nulls first" (i.e. null sorted as +inf)
- // Current behavior is to sort nulls last. This is wrong.
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp order by deptId desc")
- .returns(
- "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n"
- + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n" + "DEPTID=31; LASTNAME=Rafferty\n")
- .planContains(Order.class);
- }
-
- @Test
- public void testOrderBy() throws Exception {
- // no sort order specified is implicitly "asc", and asc is "nulls last"
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select * from emp order by deptId")
- .returns(
- "DEPTID=31; LASTNAME=Rafferty\n"
- + "DEPTID=33; LASTNAME=Jones\n"
- + "DEPTID=33; LASTNAME=Steinberg\n"
- + "DEPTID=34; LASTNAME=Robinson\n"
- + "DEPTID=34; LASTNAME=Smith\n"
- + "DEPTID=null; LASTNAME=John\n")
- .planContains(Order.class);
- }
-
- @Test
- public void testLimit() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select LASTNAME from emp limit 2")
- .returns("LASTNAME=Rafferty\n" +
- "LASTNAME=Jones")
- .planContains(Limit.class);
- }
-
-
- @Test
- public void testLimitOrderBy() throws Exception {
- TestDataConnection tdc = JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select LASTNAME from emp order by LASTNAME limit 2")
- .returns("LASTNAME=John\n" +
- "LASTNAME=Jones");
- tdc.planContains(Limit.class);
- tdc.planContains(Order.class);
-
- }
-
- @Test
- public void testOrderByWithOffset() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select LASTNAME from emp order by LASTNAME asc offset 3")
- .returns("LASTNAME=Robinson\n" +
- "LASTNAME=Smith\n" +
- "LASTNAME=Steinberg")
- .planContains(Limit.class);
-
- }
-
- @Test
- public void testOrderByWithOffsetAndFetch() throws Exception {
- JdbcAssert
- .withModel(MODEL, "HR")
- .sql("select LASTNAME from emp order by LASTNAME asc offset 3 fetch next 2 rows only")
- .returns("LASTNAME=Robinson\n" +
- "LASTNAME=Smith")
- .planContains(Limit.class);
- }
-}
-
-// End JdbcTest.java