aboutsummaryrefslogtreecommitdiff
path: root/exec/interpreter/src/test/java
diff options
context:
space:
mode:
authorJason Altekruse <altekrusejason@gmail.com>2015-03-03 15:44:32 -0800
committerJason Altekruse <altekrusejason@gmail.com>2015-03-17 12:20:54 -0700
commit1c5decc17cf38cbf4a4119d7ca19653cb19e1b53 (patch)
tree1c59c93ab76b69438653dc0ebc67d6f863600157 /exec/interpreter/src/test/java
parentbff7b9ef5a9f345908aca160a97b98f6ab187708 (diff)
DRILL-2143: Part 2 - fix interpreter and add QueryDateTimeInfo injectable to fill in holes from removing RecordBatch from UDFs - Move list of accepted injectable types into the UdfUtilities interface for easier maintenance.
Fix one more new function to remove RecordBatch from setup method. Add back UdfUtilities interface to FragmentContext lost in rebasing. Remove unneeded testcase in TestExampleQueries, remove commented out code in InterpreterGenerator previously used to handle DrillBuf injectables, now being handled by reflection to set the DrillBuf rather than the previously generated code that would use the direct reference to the incoming RecordBatch to get a buffer. Fix docs on UdfUtilities and package docs for drill/exec/expr, belongs with 2143 part 2 patch. Fix belongs with 2143, change interpreter to output a ValueHolder instead of a ValueVector in the case of a constant expression. 2143 update - Use reflection to remove boilerplate for adding new injectable types for UDFs.
Diffstat (limited to 'exec/interpreter/src/test/java')
-rw-r--r--exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java44
1 files changed, 41 insertions, 3 deletions
diff --git a/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java b/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
index a94ef9419..9df7472aa 100644
--- a/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
+++ b/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
@@ -32,7 +32,9 @@ import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.Types;
import org.apache.drill.common.util.DrillStringUtils;
import org.apache.drill.exec.expr.fn.interpreter.InterpreterEvaluator;
+import org.apache.drill.exec.expr.holders.TimeStampTZHolder;
import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.ops.QueryDateTimeInfo;
import org.apache.drill.exec.pop.PopUnitTestBase;
import org.apache.drill.exec.proto.BitControl;
import org.apache.drill.exec.record.MaterializedField;
@@ -43,8 +45,10 @@ import org.apache.drill.exec.store.mock.MockGroupScanPOP;
import org.apache.drill.exec.store.mock.MockScanBatchCreator;
import org.apache.drill.exec.store.mock.MockSubScanPOP;
import org.apache.drill.exec.vector.ValueVector;
+import org.joda.time.DateTime;
import org.junit.Test;
+import java.nio.ByteBuffer;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -94,8 +98,42 @@ public class ExpressionInterpreterTest extends PopUnitTestBase {
doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues);
}
+ @Test
+ public void interpreterDateTest() throws Exception {
+ String[] colNames = {"col1"};
+ TypeProtos.MajorType[] colTypes = {Types.optional(TypeProtos.MinorType.INT)};
+ String expressionStr = "now()";
+ BitControl.PlanFragment planFragment = BitControl.PlanFragment.getDefaultInstance();
+ QueryDateTimeInfo dateTime = new QueryDateTimeInfo(planFragment.getQueryStartTime(), planFragment.getTimeZone());
+ int timeZoneIndex = dateTime.getRootFragmentTimeZone();
+ org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
+ org.joda.time.DateTime now = new org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
+
+ long queryStartDate = now.getMillis();
+ int timezoneIndex = org.apache.drill.exec.expr.fn.impl.DateUtility.getIndex(now.getZone().toString());
+
+ TimeStampTZHolder out = new TimeStampTZHolder();
+
+ out.value = queryStartDate;
+ out.index = timezoneIndex;
+
+ ByteBuffer buffer = ByteBuffer.allocate(12);
+ buffer.putLong(out.value);
+ buffer.putInt(out.index);
+ long l = buffer.getLong(0);
+ DateTime t = new DateTime(l);
+
+ String[] expectedFirstTwoValues = {t.toString(), t.toString()};
+
+ doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues, planFragment);
+ }
+
protected void doTest(String expressionStr, String[] colNames, TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues) throws Exception {
+ doTest(expressionStr, colNames, colTypes, expectFirstTwoValues, BitControl.PlanFragment.getDefaultInstance());
+ }
+
+ protected void doTest(String expressionStr, String[] colNames, TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues, BitControl.PlanFragment planFragment) throws Exception {
RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
@@ -114,7 +152,7 @@ public class ExpressionInterpreterTest extends PopUnitTestBase {
MockGroupScanPOP.MockScanEntry entry = new MockGroupScanPOP.MockScanEntry(10, columns);
MockSubScanPOP scanPOP = new MockSubScanPOP("testTable", java.util.Collections.singletonList(entry));
- RecordBatch batch = createMockScanBatch(bit1, scanPOP);
+ RecordBatch batch = createMockScanBatch(bit1, scanPOP, planFragment);
batch.next();
@@ -134,12 +172,12 @@ public class ExpressionInterpreterTest extends PopUnitTestBase {
}
- private RecordBatch createMockScanBatch(Drillbit bit, MockSubScanPOP scanPOP) {
+ private RecordBatch createMockScanBatch(Drillbit bit, MockSubScanPOP scanPOP, BitControl.PlanFragment planFragment) {
List<RecordBatch> children = Lists.newArrayList();
MockScanBatchCreator creator = new MockScanBatchCreator();
try {
- FragmentContext context = new FragmentContext(bit.getContext(), BitControl.PlanFragment.getDefaultInstance(), null, bit.getContext().getFunctionImplementationRegistry());
+ FragmentContext context = new FragmentContext(bit.getContext(), planFragment, null, bit.getContext().getFunctionImplementationRegistry());
return creator.getBatch(context,scanPOP, children);
} catch (Exception ex) {
throw new DrillRuntimeException("Error when setup fragment context" + ex);