DRILL-1882: Add cast function from Varbinary to date/time/timestamp Add bit comparison function
Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/4f27b094 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/4f27b094 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/4f27b094 Branch: refs/heads/master Commit: 4f27b0943d73a9e06474a4a2941976c3d2f55c3e Parents: f516a20 Author: Mehant Baid <meha...@gmail.com> Authored: Thu Dec 4 00:35:02 2014 -0800 Committer: Mehant Baid <meha...@gmail.com> Committed: Wed Dec 17 18:52:14 2014 -0800 ---------------------------------------------------------------------- exec/java-exec/src/main/codegen/data/Casts.tdd | 4 ++ .../main/codegen/templates/CastVarCharDate.java | 2 +- .../drill/exec/expr/fn/impl/BitFunctions.java | 14 +++++++ .../exec/expr/fn/impl/CastVarBinaryToDate.java | 43 -------------------- .../drill/exec/fn/impl/TestCastFunctions.java | 38 +++++++++++++++++ 5 files changed, 57 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/4f27b094/exec/java-exec/src/main/codegen/data/Casts.tdd ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/data/Casts.tdd b/exec/java-exec/src/main/codegen/data/Casts.tdd index cdd6218..36c90c9 100644 --- a/exec/java-exec/src/main/codegen/data/Casts.tdd +++ b/exec/java-exec/src/main/codegen/data/Casts.tdd @@ -66,6 +66,10 @@ {from: "VarChar", to: "TimeStampTZ", major: "VarCharDate", alias: "timestamptztype"}, {from: "VarChar", to: "Time", major: "VarCharDate", alias: "timetype"}, + {from: "VarBinary", to: "Date", major: "VarBinaryDate", alias: "datetype"}, + {from: "VarBinary", to: "TimeStamp", major: "VarBinaryDate", alias: "timestamptype"}, + {from: "VarBinary", to: "Time", major: "VarBinaryDate", alias: "timetype"}, + {from: "Date", to: "VarChar", major: "DateVarChar", bufferLength: "10"} {from: "TimeStamp", to: "VarChar", major: "DateVarChar", bufferLength: "23"}, {from: "Time", to: "VarChar", major: "DateVarChar", bufferLength: "12"}, http://git-wip-us.apache.org/repos/asf/drill/blob/4f27b094/exec/java-exec/src/main/codegen/templates/CastVarCharDate.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/CastVarCharDate.java b/exec/java-exec/src/main/codegen/templates/CastVarCharDate.java index 7358f72..41c7855 100644 --- a/exec/java-exec/src/main/codegen/templates/CastVarCharDate.java +++ b/exec/java-exec/src/main/codegen/templates/CastVarCharDate.java @@ -18,7 +18,7 @@ <@pp.dropOutputFile /> <#list cast.types as type> -<#if type.major == "VarCharDate"> <#-- Template to convert from VarChar to Date, Time, TimeStamp, TimeStampTZ --> +<#if type.major == "VarCharDate" || type.major == "VarBinaryDate"> <#-- Template to convert from VarChar/ VarBinary to Date, Time, TimeStamp, TimeStampTZ --> <@pp.changeOutputFile name="/org/apache/drill/exec/expr/fn/impl/gcast/Cast${type.from}To${type.to}.java" /> http://git-wip-us.apache.org/repos/asf/drill/blob/4f27b094/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java index 7b24322..35e35b0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java @@ -72,5 +72,19 @@ public class BitFunctions { } } + @FunctionTemplate(names = {"equal","==","="}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class EqualsBitBit implements DrillSimpleFunc { + + @Param BitHolder left; + @Param BitHolder right; + @Output BitHolder out; + + public void setup(RecordBatch b) {} + + public void eval() { + out.value = left.value == right.value ? 1 : 0; + + } + } } http://git-wip-us.apache.org/repos/asf/drill/blob/4f27b094/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastVarBinaryToDate.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastVarBinaryToDate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastVarBinaryToDate.java deleted file mode 100644 index e45192e..0000000 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastVarBinaryToDate.java +++ /dev/null @@ -1,43 +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.exec.expr.fn.impl; - -import org.apache.drill.exec.expr.DrillSimpleFunc; -import org.apache.drill.exec.expr.annotations.FunctionTemplate; -import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionCostCategory; -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(names = {"castDATE", "datetype"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.NULL_IF_NULL, costCategory = FunctionCostCategory.COMPLEX) -public class CastVarBinaryToDate implements DrillSimpleFunc { - - @Param VarBinaryHolder in; - @Output DateHolder out; - - public void setup(RecordBatch incoming) { - } - - public void eval() { - out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getDate(in.buffer, in.start, in.end); - } - } http://git-wip-us.apache.org/repos/asf/drill/blob/4f27b094/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java new file mode 100644 index 0000000..cbd9d5f --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java @@ -0,0 +1,38 @@ +/** + * 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.fn.impl; + + +import org.apache.drill.BaseTestQuery; +import org.junit.Test; + +import java.util.Date; + +public class TestCastFunctions extends BaseTestQuery { + + @Test + public void testVarbinaryToDate() throws Exception { + testBuilder() + .sqlQuery("select count(*) as cnt from cp.`employee.json` where (cast(convert_to(birth_date, 'utf8') as date)) = date '1961-08-26'") + .unOrdered() + .baselineColumns("cnt") + .baselineValues(1l) + .build().run(); + } + +}