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/05/14 02:26:49 UTC
[1/4] git commit: DRILL-635: Fix run-time code generation bug for
case expression, when the holder of return type does not have value field.
Repository: incubator-drill
Updated Branches:
refs/heads/master e7a486d78 -> ea72a380e
DRILL-635: Fix run-time code generation bug for case expression, when the holder of return type does not have value field.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/8e1865c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/8e1865c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/8e1865c0
Branch: refs/heads/master
Commit: 8e1865c0e4986b4bc361ef295f77ce9e9833c94a
Parents: a4a02ef
Author: Jinfeng Ni <jn...@maprtech.com>
Authored: Mon May 12 13:19:55 2014 -0700
Committer: Aditya Kishore <ad...@maprtech.com>
Committed: Tue May 13 15:27:38 2014 -0700
----------------------------------------------------------------------
.../drill/exec/expr/EvaluationVisitor.java | 23 ++++++-------
.../exec/expr/fn/DrillSimpleFuncHolder.java | 35 +++++++++++---------
.../org/apache/drill/TestExampleQueries.java | 10 ++++++
3 files changed, 40 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8e1865c0/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 d700bf3..731ab6b 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
@@ -162,10 +162,10 @@ public class EvaluationVisitor {
if (thenExpr.isOptional()) {
JConditional newCond = jc._then()._if(thenExpr.getIsSet());
JBlock b = newCond._then();
- b.assign(output.getValue(), thenExpr.getValue());
+ b.assign(output.getHolder(), thenExpr.getHolder());
b.assign(output.getIsSet(), thenExpr.getIsSet());
} else {
- jc._then().assign(output.getValue(), thenExpr.getValue());
+ jc._then().assign(output.getHolder(), thenExpr.getHolder());
}
}
@@ -174,11 +174,10 @@ public class EvaluationVisitor {
if (elseExpr.isOptional()) {
JConditional newCond = jc._else()._if(elseExpr.getIsSet());
JBlock b = newCond._then();
- b.assign(output.getValue(), elseExpr.getValue());
+ b.assign(output.getHolder(), elseExpr.getHolder());
b.assign(output.getIsSet(), elseExpr.getIsSet());
} else {
- jc._else().assign(output.getValue(), elseExpr.getValue());
-
+ jc._else().assign(output.getHolder(), elseExpr.getHolder());
}
local.add(conditionalBlock);
return output;
@@ -336,7 +335,7 @@ public class EvaluationVisitor {
JExpression componentVariable = indexVariable.shrz(JExpr.lit(16));
if (e.isSuperReader()) {
- vv1 = ((JExpression) vv1.component(componentVariable));
+ vv1 = (vv1.component(componentVariable));
indexVariable = indexVariable.band(JExpr.lit((int) Character.MAX_VALUE));
}
@@ -467,7 +466,7 @@ public class EvaluationVisitor {
JType holderType = generator.getHolderType(majorType);
JVar var = generator.declareClassField("string", holderType);
JExpression stringLiteral = JExpr.lit(e.value);
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getVarCharHolder").arg(stringLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getVarCharHolder").arg(stringLiteral));
return new HoldingContainer(majorType, var, null, null);
}
@@ -480,7 +479,7 @@ public class EvaluationVisitor {
JVar var = generator.declareClassField("intervalday", holderType);
JExpression dayLiteral = JExpr.lit(e.getIntervalDay());
JExpression millisLiteral = JExpr.lit(e.getIntervalMillis());
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getIntervalDayHolder").arg(dayLiteral).arg(millisLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getIntervalDayHolder").arg(dayLiteral).arg(millisLiteral));
return new HoldingContainer(majorType, var, null, null);
}
@@ -493,7 +492,7 @@ public class EvaluationVisitor {
JExpression valueLiteral = JExpr.lit(e.getIntFromDecimal());
JExpression scaleLiteral = JExpr.lit(e.getScale());
JExpression precisionLiteral = JExpr.lit(e.getPrecision());
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getDecimal9Holder").arg(valueLiteral).arg(scaleLiteral).arg(precisionLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getDecimal9Holder").arg(valueLiteral).arg(scaleLiteral).arg(precisionLiteral));
return new HoldingContainer(majorType, var, null, null);
}
@@ -506,7 +505,7 @@ public class EvaluationVisitor {
JExpression valueLiteral = JExpr.lit(e.getLongFromDecimal());
JExpression scaleLiteral = JExpr.lit(e.getScale());
JExpression precisionLiteral = JExpr.lit(e.getPrecision());
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getDecimal18Holder").arg(valueLiteral).arg(scaleLiteral).arg(precisionLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getDecimal18Holder").arg(valueLiteral).arg(scaleLiteral).arg(precisionLiteral));
return new HoldingContainer(majorType, var, null, null);
}
@@ -518,7 +517,7 @@ public class EvaluationVisitor {
JType holderType = generator.getHolderType(majorType);
JVar var = generator.declareClassField("dec28", holderType);
JExpression stringLiteral = JExpr.lit(e.getBigDecimal().toString());
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getDecimal28Holder").arg(stringLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getDecimal28Holder").arg(stringLiteral));
return new HoldingContainer(majorType, var, null, null);
}
@@ -530,7 +529,7 @@ public class EvaluationVisitor {
JType holderType = generator.getHolderType(majorType);
JVar var = generator.declareClassField("dec38", holderType);
JExpression stringLiteral = JExpr.lit(e.getBigDecimal().toString());
- setup.assign(var, ((JClass)generator.getModel().ref(ValueHolderHelper.class)).staticInvoke("getVarCharHolder").arg(stringLiteral));
+ setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getVarCharHolder").arg(stringLiteral));
return new HoldingContainer(majorType, var, null, null);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8e1865c0/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
index 0460ec4..01fc514 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
@@ -40,13 +40,13 @@ import com.sun.codemodel.JVar;
class DrillSimpleFuncHolder extends DrillFuncHolder{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSimpleFuncHolder.class);
-
+
private final String setupBody;
private final String evalBody;
private final String resetBody;
private final String cleanupBody;
-
-
+
+
public DrillSimpleFuncHolder(FunctionScope scope, NullHandling nullHandling, boolean isBinaryCommutative, boolean isRandom,
String[] registeredNames, ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] workspaceVars,
Map<String, String> methods, List<String> imports) {
@@ -56,16 +56,16 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
resetBody = methods.get("reset");
cleanupBody = methods.get("cleanup");
Preconditions.checkNotNull(evalBody);
-
+
}
public boolean isNested(){
return false;
}
-
+
public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars){
- //If the function's annotation specifies a parameter has to be constant expression, but the HoldingContainer
- //for the argument is not, then raise exception.
+ //If the function's annotation specifies a parameter has to be constant expression, but the HoldingContainer
+ //for the argument is not, then raise exception.
for(int i =0; i < inputVariables.length; i++){
if (parameters[i].isConstant && !inputVariables[i].isConstant()) {
throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", parameters[i].name, this.getRegisteredNames()[0]));
@@ -77,11 +77,11 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
generateBody(g, BlockType.CLEANUP, cleanupBody, null, workspaceJVars, false);
return c;
}
-
+
protected HoldingContainer generateEvalBody(ClassGenerator<?> g, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars) {
-
- //g.getBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", functionName));
-
+
+ g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", registeredNames[0]));
+
JBlock sub = new JBlock(true, true);
JBlock topSub = sub;
HoldingContainer out = null;
@@ -99,7 +99,7 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
}
}
}
-
+
if(e != null){
// if at least one expression must be checked, set up the conditional.
returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
@@ -110,18 +110,21 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
sub = jc._else();
}
}
-
+
if(out == null) out = g.declare(returnValueType);
-
+
// add the subblock after the out declaration.
g.getEvalBlock().add(topSub);
-
-
+
+
JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValueType), returnValue.name, JExpr._new(g.getHolderType(returnValueType)));
addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);
if (sub != topSub) sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
sub.assign(out.getHolder(), internalOutput);
if (sub != topSub) sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
+
+ g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));
+
return out;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8e1865c0/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index 69552f9..99940f4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -39,6 +39,16 @@ public class TestExampleQueries extends BaseTestQuery{
}
@Test
+ public void testCaseReturnValueVarChar() throws Exception{
+ test("select case when employee_id < 1000 then 'ABC' else 'DEF' end from cp.`employee.json` limit 5");
+ }
+
+ @Test
+ public void testCaseReturnValueBigInt() throws Exception{
+ test("select case when employee_id < 1000 then 1000 else 2000 end from cp.`employee.json` limit 5" );
+ }
+
+ @Test
public void testSelectWithLimit() throws Exception{
test("select employee_id, first_name, last_name from cp.`employee.json` order by employee_id limit 5 offset 10");
}
Re: [4/4] git commit: DRILL-718: Return complex types as JSON string.
Posted by Mehant Baid <ba...@gmail.com>.
Yes!
We sub-classed HashMap and ArrayList used internally by Map, RepeatedMap
and RepeatedList vectors to override the toString() method to return
JSON string.
Thanks
Mehant
On 5/13/14, 6:45 PM, Timothy Chen wrote:
> Does this means any complex type will be displayed JSON strings to the
> user from the interactive shell as well?
>
> Tim
>
> On Tue, May 13, 2014 at 5:26 PM, <ja...@apache.org> wrote:
>> DRILL-718: Return complex types as JSON string.
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/ea72a380
>> Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/ea72a380
>> Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/ea72a380
>>
>> Branch: refs/heads/master
>> Commit: ea72a380e875aaaa126510116742be659016d98f
>> Parents: 4b57652
>> Author: Mehant Baid <me...@gmail.com>
>> Authored: Tue May 13 15:07:54 2014 -0700
>> Committer: Aditya Kishore <ad...@maprtech.com>
>> Committed: Tue May 13 16:06:03 2014 -0700
>>
>> ----------------------------------------------------------------------
>> .../src/main/codegen/includes/vv_imports.ftl | 1 +
>> .../codegen/templates/RepeatedValueVectors.java | 2 +-
>> .../src/main/codegen/templates/TypeHelper.java | 5 ++
>> .../drill/exec/util/JsonStringArrayList.java | 46 ++++++++++++++++++
>> .../drill/exec/util/JsonStringHashMap.java | 50 ++++++++++++++++++++
>> .../apache/drill/exec/util/TextSerializer.java | 38 +++++++++++++++
>> .../drill/exec/vector/complex/MapVector.java | 3 +-
>> .../exec/vector/complex/RepeatedListVector.java | 3 +-
>> .../exec/vector/complex/RepeatedMapVector.java | 3 +-
>> .../exec/vector/complex/fn/JsonReader.java | 2 +-
>> .../exec/store/json/JsonRecordReader2Test.java | 2 +
>> 11 files changed, 150 insertions(+), 5 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
>> index 71404d3..114ecbe 100644
>> --- a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
>> +++ b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
>> @@ -38,6 +38,7 @@ import org.apache.drill.exec.vector.complex.impl.*;
>> import org.apache.drill.exec.vector.complex.writer.*;
>> import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
>> import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
>> +import org.apache.drill.exec.util.JsonStringArrayList;
>>
>> import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
>>
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
>> index 537c7fd..cac87c5 100644
>> --- a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
>> +++ b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
>> @@ -296,7 +296,7 @@ package org.apache.drill.exec.vector;
>> }
>>
>> public List<${friendlyType}> getObject(int index) {
>> - List<${friendlyType}> vals = Lists.newArrayList();
>> + List<${friendlyType}> vals = new JsonStringArrayList();
>> int start = offsets.getAccessor().get(index) - sliceOffset;
>> int end = offsets.getAccessor().get(index+1) - sliceOffset;
>> for(int i = start; i < end; i++){
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/TypeHelper.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/codegen/templates/TypeHelper.java b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
>> index 4755e92..f2d66d2 100644
>> --- a/exec/java-exec/src/main/codegen/templates/TypeHelper.java
>> +++ b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
>> @@ -66,7 +66,12 @@ public class TypeHelper {
>> }
>> </#list>
>> </#list>
>> + case MAP:
>> + case REPEATMAP:
>> + case LIST:
>> + return new GenericAccessor(vector);
>> }
>> +
>> throw new UnsupportedOperationException();
>> }
>>
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
>> new file mode 100644
>> index 0000000..bc378a1
>> --- /dev/null
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.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.util;
>> +
>> +import com.fasterxml.jackson.core.JsonProcessingException;
>> +import com.fasterxml.jackson.databind.ObjectMapper;
>> +import com.fasterxml.jackson.databind.module.SimpleModule;
>> +import org.apache.hadoop.io.Text;
>> +
>> +import java.util.ArrayList;
>> +
>> +public class JsonStringArrayList extends ArrayList {
>> +
>> + private static ObjectMapper mapper;
>> +
>> + static {
>> + mapper = new ObjectMapper();
>> + SimpleModule serializer = new SimpleModule("TextSerializer")
>> + .addSerializer(Text.class, new TextSerializer());
>> + mapper.registerModule(serializer);
>> + }
>> +
>> + @Override
>> + public final String toString() {
>> + try {
>> + return mapper.writeValueAsString(this);
>> + } catch(JsonProcessingException e) {
>> + throw new IllegalStateException("Cannot serialize array list to JSON string", e);
>> + }
>> + }
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
>> new file mode 100644
>> index 0000000..124252a
>> --- /dev/null
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
>> @@ -0,0 +1,50 @@
>> +/**
>> + * 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 com.fasterxml.jackson.core.JsonProcessingException;
>> +import com.fasterxml.jackson.databind.ObjectMapper;
>> +import com.fasterxml.jackson.databind.module.SimpleModule;
>> +import org.apache.hadoop.io.Text;
>> +
>> +import java.util.HashMap;
>> +
>> +/*
>> + * Simple class that extends the regular java.util.HashMap but overrides the
>> + * toString() method of the HashMap class to produce a JSON string instead
>> + */
>> +public class JsonStringHashMap extends HashMap {
>> +
>> + private static ObjectMapper mapper;
>> +
>> + static {
>> + mapper = new ObjectMapper();
>> + SimpleModule serializer = new SimpleModule("TextSerializer")
>> + .addSerializer(Text.class, new TextSerializer());
>> + mapper.registerModule(serializer);
>> + }
>> +
>> + @Override
>> + public final String toString() {
>> + try {
>> + return mapper.writeValueAsString(this);
>> + } catch(JsonProcessingException e) {
>> + throw new IllegalStateException("Cannot serialize hash map to JSON string", e);
>> + }
>> + }
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
>> new file mode 100644
>> index 0000000..3070592
>> --- /dev/null
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.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.util;
>> +
>> +import com.fasterxml.jackson.core.JsonGenerationException;
>> +import com.fasterxml.jackson.core.JsonGenerator;
>> +import com.fasterxml.jackson.databind.SerializerProvider;
>> +import com.fasterxml.jackson.databind.ser.std.StdSerializer;
>> +import org.apache.hadoop.io.Text;
>> +
>> +import java.io.IOException;
>> +
>> +public class TextSerializer extends StdSerializer<Text> {
>> +
>> + public TextSerializer() {
>> + super(Text.class);
>> + }
>> +
>> + @Override
>> + public void serialize(Text text, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
>> + jsonGenerator.writeString(text.toString());
>> + }
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
>> index 91c0be5..9b2e119 100644
>> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
>> @@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
>> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
>> import org.apache.drill.exec.record.MaterializedField;
>> import org.apache.drill.exec.record.TransferPair;
>> +import org.apache.drill.exec.util.JsonStringHashMap;
>> import org.apache.drill.exec.vector.ValueVector;
>> import org.apache.drill.exec.vector.complex.RepeatedMapVector.MapSingleCopier;
>> import org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl;
>> @@ -316,7 +317,7 @@ public class MapVector extends AbstractContainerVector {
>>
>> @Override
>> public Object getObject(int index) {
>> - Map<String, Object> vv = Maps.newHashMap();
>> + Map<String, Object> vv = new JsonStringHashMap();
>> for(Map.Entry<String, ValueVector> e : vectors.entrySet()){
>> ValueVector v = e.getValue();
>> String k = e.getKey();
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
>> index 93930b5..88d858a 100644
>> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
>> @@ -37,6 +37,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
>> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
>> import org.apache.drill.exec.record.MaterializedField;
>> import org.apache.drill.exec.record.TransferPair;
>> +import org.apache.drill.exec.util.JsonStringArrayList;
>> import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
>> import org.apache.drill.exec.vector.UInt4Vector;
>> import org.apache.drill.exec.vector.ValueVector;
>> @@ -155,7 +156,7 @@ public class RepeatedListVector extends AbstractContainerVector implements Repea
>>
>> @Override
>> public Object getObject(int index) {
>> - List<Object> l = Lists.newArrayList();
>> + List<Object> l = new JsonStringArrayList();
>> int end = offsets.getAccessor().get(index+1);
>> for(int i = offsets.getAccessor().get(index); i < end; i++){
>> l.add(vector.getAccessor().getObject(i));
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
>> index 2492cc8..22471f0 100644
>> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
>> @@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
>> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
>> import org.apache.drill.exec.record.MaterializedField;
>> import org.apache.drill.exec.record.TransferPair;
>> +import org.apache.drill.exec.util.JsonStringArrayList;
>> import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
>> import org.apache.drill.exec.vector.UInt4Vector;
>> import org.apache.drill.exec.vector.ValueVector;
>> @@ -348,7 +349,7 @@ public class RepeatedMapVector extends AbstractContainerVector implements Repeat
>>
>> @Override
>> public Object getObject(int index) {
>> - List<Object> l = Lists.newArrayList();
>> + List<Object> l = new JsonStringArrayList();
>> int end = offsets.getAccessor().get(index+1);
>> for(int i = offsets.getAccessor().get(index); i < end; i++){
>> Map<String, Object> vv = Maps.newHashMap();
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
>> index 761bc79..e5d4b5b 100644
>> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
>> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
>> @@ -221,7 +221,7 @@ public class JsonReader {
>> vh.start = 0;
>> vh.end = b.length;
>> list.varChar().write(vh);
>> -
>> + break;
>> default:
>> throw new IllegalStateException("Unexpected token " + parser.getCurrentToken());
>> }
>>
>> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
>> ----------------------------------------------------------------------
>> diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
>> index 1372219..ad46326 100644
>> --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
>> +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
>> @@ -27,6 +27,8 @@ public class JsonRecordReader2Test extends BaseTestQuery{
>> public void testComplexJsonInput() throws Exception{
>> // test("select z[0]['orange'] from cp.`jsoninput/input2.json` limit 10");
>> test("select `integer`, x['y'] as x1, x['y'] as x2, z[0], z[0]['orange'], z[1]['pink'] from cp.`jsoninput/input2.json` limit 10");
>> + test("select x from cp.`jsoninput/input2.json`");
>> +
>> // test("select z[0] from cp.`jsoninput/input2.json` limit 10");
>> }
>>
>>
Re: [4/4] git commit: DRILL-718: Return complex types as JSON string.
Posted by Timothy Chen <tn...@gmail.com>.
Does this means any complex type will be displayed JSON strings to the
user from the interactive shell as well?
Tim
On Tue, May 13, 2014 at 5:26 PM, <ja...@apache.org> wrote:
> DRILL-718: Return complex types as JSON string.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
> Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/ea72a380
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/ea72a380
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/ea72a380
>
> Branch: refs/heads/master
> Commit: ea72a380e875aaaa126510116742be659016d98f
> Parents: 4b57652
> Author: Mehant Baid <me...@gmail.com>
> Authored: Tue May 13 15:07:54 2014 -0700
> Committer: Aditya Kishore <ad...@maprtech.com>
> Committed: Tue May 13 16:06:03 2014 -0700
>
> ----------------------------------------------------------------------
> .../src/main/codegen/includes/vv_imports.ftl | 1 +
> .../codegen/templates/RepeatedValueVectors.java | 2 +-
> .../src/main/codegen/templates/TypeHelper.java | 5 ++
> .../drill/exec/util/JsonStringArrayList.java | 46 ++++++++++++++++++
> .../drill/exec/util/JsonStringHashMap.java | 50 ++++++++++++++++++++
> .../apache/drill/exec/util/TextSerializer.java | 38 +++++++++++++++
> .../drill/exec/vector/complex/MapVector.java | 3 +-
> .../exec/vector/complex/RepeatedListVector.java | 3 +-
> .../exec/vector/complex/RepeatedMapVector.java | 3 +-
> .../exec/vector/complex/fn/JsonReader.java | 2 +-
> .../exec/store/json/JsonRecordReader2Test.java | 2 +
> 11 files changed, 150 insertions(+), 5 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
> index 71404d3..114ecbe 100644
> --- a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
> +++ b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
> @@ -38,6 +38,7 @@ import org.apache.drill.exec.vector.complex.impl.*;
> import org.apache.drill.exec.vector.complex.writer.*;
> import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
> import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
> +import org.apache.drill.exec.util.JsonStringArrayList;
>
> import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
> index 537c7fd..cac87c5 100644
> --- a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
> +++ b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
> @@ -296,7 +296,7 @@ package org.apache.drill.exec.vector;
> }
>
> public List<${friendlyType}> getObject(int index) {
> - List<${friendlyType}> vals = Lists.newArrayList();
> + List<${friendlyType}> vals = new JsonStringArrayList();
> int start = offsets.getAccessor().get(index) - sliceOffset;
> int end = offsets.getAccessor().get(index+1) - sliceOffset;
> for(int i = start; i < end; i++){
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/TypeHelper.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/codegen/templates/TypeHelper.java b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
> index 4755e92..f2d66d2 100644
> --- a/exec/java-exec/src/main/codegen/templates/TypeHelper.java
> +++ b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
> @@ -66,7 +66,12 @@ public class TypeHelper {
> }
> </#list>
> </#list>
> + case MAP:
> + case REPEATMAP:
> + case LIST:
> + return new GenericAccessor(vector);
> }
> +
> throw new UnsupportedOperationException();
> }
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
> new file mode 100644
> index 0000000..bc378a1
> --- /dev/null
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.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.util;
> +
> +import com.fasterxml.jackson.core.JsonProcessingException;
> +import com.fasterxml.jackson.databind.ObjectMapper;
> +import com.fasterxml.jackson.databind.module.SimpleModule;
> +import org.apache.hadoop.io.Text;
> +
> +import java.util.ArrayList;
> +
> +public class JsonStringArrayList extends ArrayList {
> +
> + private static ObjectMapper mapper;
> +
> + static {
> + mapper = new ObjectMapper();
> + SimpleModule serializer = new SimpleModule("TextSerializer")
> + .addSerializer(Text.class, new TextSerializer());
> + mapper.registerModule(serializer);
> + }
> +
> + @Override
> + public final String toString() {
> + try {
> + return mapper.writeValueAsString(this);
> + } catch(JsonProcessingException e) {
> + throw new IllegalStateException("Cannot serialize array list to JSON string", e);
> + }
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
> new file mode 100644
> index 0000000..124252a
> --- /dev/null
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
> @@ -0,0 +1,50 @@
> +/**
> + * 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 com.fasterxml.jackson.core.JsonProcessingException;
> +import com.fasterxml.jackson.databind.ObjectMapper;
> +import com.fasterxml.jackson.databind.module.SimpleModule;
> +import org.apache.hadoop.io.Text;
> +
> +import java.util.HashMap;
> +
> +/*
> + * Simple class that extends the regular java.util.HashMap but overrides the
> + * toString() method of the HashMap class to produce a JSON string instead
> + */
> +public class JsonStringHashMap extends HashMap {
> +
> + private static ObjectMapper mapper;
> +
> + static {
> + mapper = new ObjectMapper();
> + SimpleModule serializer = new SimpleModule("TextSerializer")
> + .addSerializer(Text.class, new TextSerializer());
> + mapper.registerModule(serializer);
> + }
> +
> + @Override
> + public final String toString() {
> + try {
> + return mapper.writeValueAsString(this);
> + } catch(JsonProcessingException e) {
> + throw new IllegalStateException("Cannot serialize hash map to JSON string", e);
> + }
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
> new file mode 100644
> index 0000000..3070592
> --- /dev/null
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.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.util;
> +
> +import com.fasterxml.jackson.core.JsonGenerationException;
> +import com.fasterxml.jackson.core.JsonGenerator;
> +import com.fasterxml.jackson.databind.SerializerProvider;
> +import com.fasterxml.jackson.databind.ser.std.StdSerializer;
> +import org.apache.hadoop.io.Text;
> +
> +import java.io.IOException;
> +
> +public class TextSerializer extends StdSerializer<Text> {
> +
> + public TextSerializer() {
> + super(Text.class);
> + }
> +
> + @Override
> + public void serialize(Text text, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
> + jsonGenerator.writeString(text.toString());
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
> index 91c0be5..9b2e119 100644
> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
> @@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
> import org.apache.drill.exec.record.MaterializedField;
> import org.apache.drill.exec.record.TransferPair;
> +import org.apache.drill.exec.util.JsonStringHashMap;
> import org.apache.drill.exec.vector.ValueVector;
> import org.apache.drill.exec.vector.complex.RepeatedMapVector.MapSingleCopier;
> import org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl;
> @@ -316,7 +317,7 @@ public class MapVector extends AbstractContainerVector {
>
> @Override
> public Object getObject(int index) {
> - Map<String, Object> vv = Maps.newHashMap();
> + Map<String, Object> vv = new JsonStringHashMap();
> for(Map.Entry<String, ValueVector> e : vectors.entrySet()){
> ValueVector v = e.getValue();
> String k = e.getKey();
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
> index 93930b5..88d858a 100644
> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
> @@ -37,6 +37,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
> import org.apache.drill.exec.record.MaterializedField;
> import org.apache.drill.exec.record.TransferPair;
> +import org.apache.drill.exec.util.JsonStringArrayList;
> import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
> import org.apache.drill.exec.vector.UInt4Vector;
> import org.apache.drill.exec.vector.ValueVector;
> @@ -155,7 +156,7 @@ public class RepeatedListVector extends AbstractContainerVector implements Repea
>
> @Override
> public Object getObject(int index) {
> - List<Object> l = Lists.newArrayList();
> + List<Object> l = new JsonStringArrayList();
> int end = offsets.getAccessor().get(index+1);
> for(int i = offsets.getAccessor().get(index); i < end; i++){
> l.add(vector.getAccessor().getObject(i));
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
> index 2492cc8..22471f0 100644
> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
> @@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
> import org.apache.drill.exec.proto.UserBitShared.SerializedField;
> import org.apache.drill.exec.record.MaterializedField;
> import org.apache.drill.exec.record.TransferPair;
> +import org.apache.drill.exec.util.JsonStringArrayList;
> import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
> import org.apache.drill.exec.vector.UInt4Vector;
> import org.apache.drill.exec.vector.ValueVector;
> @@ -348,7 +349,7 @@ public class RepeatedMapVector extends AbstractContainerVector implements Repeat
>
> @Override
> public Object getObject(int index) {
> - List<Object> l = Lists.newArrayList();
> + List<Object> l = new JsonStringArrayList();
> int end = offsets.getAccessor().get(index+1);
> for(int i = offsets.getAccessor().get(index); i < end; i++){
> Map<String, Object> vv = Maps.newHashMap();
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
> index 761bc79..e5d4b5b 100644
> --- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
> +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
> @@ -221,7 +221,7 @@ public class JsonReader {
> vh.start = 0;
> vh.end = b.length;
> list.varChar().write(vh);
> -
> + break;
> default:
> throw new IllegalStateException("Unexpected token " + parser.getCurrentToken());
> }
>
> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
> ----------------------------------------------------------------------
> diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
> index 1372219..ad46326 100644
> --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
> +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
> @@ -27,6 +27,8 @@ public class JsonRecordReader2Test extends BaseTestQuery{
> public void testComplexJsonInput() throws Exception{
> // test("select z[0]['orange'] from cp.`jsoninput/input2.json` limit 10");
> test("select `integer`, x['y'] as x1, x['y'] as x2, z[0], z[0]['orange'], z[1]['pink'] from cp.`jsoninput/input2.json` limit 10");
> + test("select x from cp.`jsoninput/input2.json`");
> +
> // test("select z[0] from cp.`jsoninput/input2.json` limit 10");
> }
>
>
[4/4] git commit: DRILL-718: Return complex types as JSON string.
Posted by ja...@apache.org.
DRILL-718: Return complex types as JSON string.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/ea72a380
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/ea72a380
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/ea72a380
Branch: refs/heads/master
Commit: ea72a380e875aaaa126510116742be659016d98f
Parents: 4b57652
Author: Mehant Baid <me...@gmail.com>
Authored: Tue May 13 15:07:54 2014 -0700
Committer: Aditya Kishore <ad...@maprtech.com>
Committed: Tue May 13 16:06:03 2014 -0700
----------------------------------------------------------------------
.../src/main/codegen/includes/vv_imports.ftl | 1 +
.../codegen/templates/RepeatedValueVectors.java | 2 +-
.../src/main/codegen/templates/TypeHelper.java | 5 ++
.../drill/exec/util/JsonStringArrayList.java | 46 ++++++++++++++++++
.../drill/exec/util/JsonStringHashMap.java | 50 ++++++++++++++++++++
.../apache/drill/exec/util/TextSerializer.java | 38 +++++++++++++++
.../drill/exec/vector/complex/MapVector.java | 3 +-
.../exec/vector/complex/RepeatedListVector.java | 3 +-
.../exec/vector/complex/RepeatedMapVector.java | 3 +-
.../exec/vector/complex/fn/JsonReader.java | 2 +-
.../exec/store/json/JsonRecordReader2Test.java | 2 +
11 files changed, 150 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
index 71404d3..114ecbe 100644
--- a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
+++ b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl
@@ -38,6 +38,7 @@ import org.apache.drill.exec.vector.complex.impl.*;
import org.apache.drill.exec.vector.complex.writer.*;
import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
+import org.apache.drill.exec.util.JsonStringArrayList;
import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
index 537c7fd..cac87c5 100644
--- a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
+++ b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
@@ -296,7 +296,7 @@ package org.apache.drill.exec.vector;
}
public List<${friendlyType}> getObject(int index) {
- List<${friendlyType}> vals = Lists.newArrayList();
+ List<${friendlyType}> vals = new JsonStringArrayList();
int start = offsets.getAccessor().get(index) - sliceOffset;
int end = offsets.getAccessor().get(index+1) - sliceOffset;
for(int i = start; i < end; i++){
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/codegen/templates/TypeHelper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/TypeHelper.java b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
index 4755e92..f2d66d2 100644
--- a/exec/java-exec/src/main/codegen/templates/TypeHelper.java
+++ b/exec/java-exec/src/main/codegen/templates/TypeHelper.java
@@ -66,7 +66,12 @@ public class TypeHelper {
}
</#list>
</#list>
+ case MAP:
+ case REPEATMAP:
+ case LIST:
+ return new GenericAccessor(vector);
}
+
throw new UnsupportedOperationException();
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java
new file mode 100644
index 0000000..bc378a1
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.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.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.apache.hadoop.io.Text;
+
+import java.util.ArrayList;
+
+public class JsonStringArrayList extends ArrayList {
+
+ private static ObjectMapper mapper;
+
+ static {
+ mapper = new ObjectMapper();
+ SimpleModule serializer = new SimpleModule("TextSerializer")
+ .addSerializer(Text.class, new TextSerializer());
+ mapper.registerModule(serializer);
+ }
+
+ @Override
+ public final String toString() {
+ try {
+ return mapper.writeValueAsString(this);
+ } catch(JsonProcessingException e) {
+ throw new IllegalStateException("Cannot serialize array list to JSON string", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
new file mode 100644
index 0000000..124252a
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java
@@ -0,0 +1,50 @@
+/**
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.apache.hadoop.io.Text;
+
+import java.util.HashMap;
+
+/*
+ * Simple class that extends the regular java.util.HashMap but overrides the
+ * toString() method of the HashMap class to produce a JSON string instead
+ */
+public class JsonStringHashMap extends HashMap {
+
+ private static ObjectMapper mapper;
+
+ static {
+ mapper = new ObjectMapper();
+ SimpleModule serializer = new SimpleModule("TextSerializer")
+ .addSerializer(Text.class, new TextSerializer());
+ mapper.registerModule(serializer);
+ }
+
+ @Override
+ public final String toString() {
+ try {
+ return mapper.writeValueAsString(this);
+ } catch(JsonProcessingException e) {
+ throw new IllegalStateException("Cannot serialize hash map to JSON string", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.java
new file mode 100644
index 0000000..3070592
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/TextSerializer.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.util;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import org.apache.hadoop.io.Text;
+
+import java.io.IOException;
+
+public class TextSerializer extends StdSerializer<Text> {
+
+ public TextSerializer() {
+ super(Text.class);
+ }
+
+ @Override
+ public void serialize(Text text, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
+ jsonGenerator.writeString(text.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
index 91c0be5..9b2e119 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/MapVector.java
@@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
import org.apache.drill.exec.proto.UserBitShared.SerializedField;
import org.apache.drill.exec.record.MaterializedField;
import org.apache.drill.exec.record.TransferPair;
+import org.apache.drill.exec.util.JsonStringHashMap;
import org.apache.drill.exec.vector.ValueVector;
import org.apache.drill.exec.vector.complex.RepeatedMapVector.MapSingleCopier;
import org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl;
@@ -316,7 +317,7 @@ public class MapVector extends AbstractContainerVector {
@Override
public Object getObject(int index) {
- Map<String, Object> vv = Maps.newHashMap();
+ Map<String, Object> vv = new JsonStringHashMap();
for(Map.Entry<String, ValueVector> e : vectors.entrySet()){
ValueVector v = e.getValue();
String k = e.getKey();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
index 93930b5..88d858a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedListVector.java
@@ -37,6 +37,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
import org.apache.drill.exec.proto.UserBitShared.SerializedField;
import org.apache.drill.exec.record.MaterializedField;
import org.apache.drill.exec.record.TransferPair;
+import org.apache.drill.exec.util.JsonStringArrayList;
import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
import org.apache.drill.exec.vector.UInt4Vector;
import org.apache.drill.exec.vector.ValueVector;
@@ -155,7 +156,7 @@ public class RepeatedListVector extends AbstractContainerVector implements Repea
@Override
public Object getObject(int index) {
- List<Object> l = Lists.newArrayList();
+ List<Object> l = new JsonStringArrayList();
int end = offsets.getAccessor().get(index+1);
for(int i = offsets.getAccessor().get(index); i < end; i++){
l.add(vector.getAccessor().getObject(i));
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
index 2492cc8..22471f0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/RepeatedMapVector.java
@@ -36,6 +36,7 @@ import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
import org.apache.drill.exec.proto.UserBitShared.SerializedField;
import org.apache.drill.exec.record.MaterializedField;
import org.apache.drill.exec.record.TransferPair;
+import org.apache.drill.exec.util.JsonStringArrayList;
import org.apache.drill.exec.vector.RepeatedFixedWidthVector;
import org.apache.drill.exec.vector.UInt4Vector;
import org.apache.drill.exec.vector.ValueVector;
@@ -348,7 +349,7 @@ public class RepeatedMapVector extends AbstractContainerVector implements Repeat
@Override
public Object getObject(int index) {
- List<Object> l = Lists.newArrayList();
+ List<Object> l = new JsonStringArrayList();
int end = offsets.getAccessor().get(index+1);
for(int i = offsets.getAccessor().get(index); i < end; i++){
Map<String, Object> vv = Maps.newHashMap();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
index 761bc79..e5d4b5b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
@@ -221,7 +221,7 @@ public class JsonReader {
vh.start = 0;
vh.end = b.length;
list.varChar().write(vh);
-
+ break;
default:
throw new IllegalStateException("Unexpected token " + parser.getCurrentToken());
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea72a380/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
index 1372219..ad46326 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/json/JsonRecordReader2Test.java
@@ -27,6 +27,8 @@ public class JsonRecordReader2Test extends BaseTestQuery{
public void testComplexJsonInput() throws Exception{
// test("select z[0]['orange'] from cp.`jsoninput/input2.json` limit 10");
test("select `integer`, x['y'] as x1, x['y'] as x2, z[0], z[0]['orange'], z[1]['pink'] from cp.`jsoninput/input2.json` limit 10");
+ test("select x from cp.`jsoninput/input2.json`");
+
// test("select z[0] from cp.`jsoninput/input2.json` limit 10");
}
[3/4] git commit: DRILL-700: Extend AvaticaDrillSqlAccessor to
support getDate(), getTime() and getTimestamp()
Posted by ja...@apache.org.
DRILL-700: Extend AvaticaDrillSqlAccessor to support getDate(), getTime() and getTimestamp()
+ Added accessor methods for getDate(), getTime() and getTimeStamp() in each of the data type's accessor class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/4b57652f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/4b57652f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/4b57652f
Branch: refs/heads/master
Commit: 4b57652f1ea0b9d6b68826b5f07d624eabf043f3
Parents: 8e1865c
Author: Mehant Baid <me...@gmail.com>
Authored: Mon May 12 12:48:28 2014 -0700
Committer: Aditya Kishore <ad...@maprtech.com>
Committed: Tue May 13 16:05:59 2014 -0700
----------------------------------------------------------------------
.../codegen/templates/FixedValueVectors.java | 17 ++++++++++-
.../codegen/templates/NullableValueVectors.java | 10 ++++++
.../main/codegen/templates/SqlAccessors.java | 27 +++++++++++++++--
.../drill/jdbc/AvaticaDrillSqlAccessor.java | 6 ++--
.../apache/drill/jdbc/test/TestJdbcQuery.java | 32 ++++++++++++++++++++
5 files changed, 85 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b57652f/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java
index 8c6c037..7193c29 100644
--- a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java
+++ b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java
@@ -272,7 +272,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F
return p.plusMonths(months).plusDays(days).plusMillis(millis);
}
- public StringBuilder getAsString(int index) {
+ public StringBuilder getAsStringBuilder(int index) {
int offsetIndex = index * ${type.width};
@@ -469,6 +469,21 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements F
Period p = new Period();
return p.plusYears(years).plusMonths(months);
}
+
+ public StringBuilder getAsStringBuilder(int index) {
+
+ int months = data.getInt(index);
+
+ int years = (months / org.apache.drill.exec.expr.fn.impl.DateUtility.yearsToMonths);
+ months = (months % org.apache.drill.exec.expr.fn.impl.DateUtility.yearsToMonths);
+
+ String yearString = (Math.abs(years) == 1) ? " year " : " years ";
+ String monthString = (Math.abs(months) == 1) ? " month " : " months ";
+
+ return(new StringBuilder().
+ append(years).append(yearString).
+ append(months).append(monthString));
+ }
<#elseif minor.class == "Time">
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b57652f/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java b/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java
index 403ba4f..08eea6e 100644
--- a/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java
+++ b/exec/java-exec/src/main/codegen/templates/NullableValueVectors.java
@@ -350,6 +350,16 @@ public final class ${className} extends BaseValueVector implements <#if type.maj
}
}
+ <#if minor.class == "Interval" || minor.class == "IntervalDay" || minor.class == "IntervalYear">
+ public StringBuilder getAsStringBuilder(int index) {
+ if (isNull(index)) {
+ return null;
+ }else{
+ return values.getAccessor().getAsStringBuilder(index);
+ }
+ }
+ </#if>
+
public int getValueCount(){
return valueCount;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b57652f/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
index 74ee9ed..b7207f9 100644
--- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
+++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
@@ -102,16 +102,37 @@ public class ${name}Accessor extends AbstractSqlAccessor{
public Timestamp getTimestamp(int index) {
return new Timestamp(ac.getObject(index).getMillis());
}
- <#elseif minor.class == "Interval" || minor.class == "IntervalDay">
+ <#elseif minor.class == "Interval" || minor.class == "IntervalDay" || minor.class == "IntervalYear">
@Override
- public byte[] getBytes(int index) {
- return null;
+ public String getString(int index) {
+ return String.valueOf(ac.getAsStringBuilder(index));
}
<#elseif minor.class.startsWith("Decimal")>
@Override
public BigDecimal getBigDecimal(int index) {
return ac.getObject(index);
}
+ <#elseif minor.class == "Date">
+ @Override
+ public Date getDate(int index) {
+ org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
+ date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return new Date(date.getMillis());
+ }
+ <#elseif minor.class == "TimeStamp">
+ @Override
+ public Timestamp getTimestamp(int index) {
+ org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
+ date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return new Timestamp(date.getMillis());
+ }
+ <#elseif minor.class == "Time">
+ @Override
+ public Time getTime(int index) {
+ org.joda.time.DateTime time = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
+ time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return new Time(time.getMillis());
+ }
<#else>
@Override
public ${javaType} get${javaType?cap_first}(int index){
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b57652f/exec/jdbc/src/main/java/org/apache/drill/jdbc/AvaticaDrillSqlAccessor.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/AvaticaDrillSqlAccessor.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/AvaticaDrillSqlAccessor.java
index 48fb6fd..d06c420 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/AvaticaDrillSqlAccessor.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/AvaticaDrillSqlAccessor.java
@@ -168,17 +168,17 @@ public class AvaticaDrillSqlAccessor implements Accessor{
@Override
public Date getDate(Calendar calendar) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return a.getDate(row());
}
@Override
public Time getTime(Calendar calendar) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return a.getTime(row());
}
@Override
public Timestamp getTimestamp(Calendar calendar) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return a.getTimestamp(row());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b57652f/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 2d26b17..2fd23d3 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -20,6 +20,7 @@ package org.apache.drill.jdbc.test;
import java.lang.Exception;
import java.lang.RuntimeException;
import java.nio.file.Paths;
+import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -751,6 +752,37 @@ public class TestJdbcQuery extends JdbcTest{
});
}
+
+ @Test
+ public void testDateTimeAccessors() throws Exception{
+ JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ Statement statement = connection.createStatement();
+
+ // show tables on view
+ ResultSet resultSet = statement.executeQuery("select date '2008-2-23', time '12:23:34', timestamp '2008-2-23 12:23:34.456', " +
+ "interval '1' year, interval '2' day " +
+ "from cp.`employee.json` limit 1");
+
+ java.sql.Date date = resultSet.getDate(1);
+ java.sql.Time time = resultSet.getTime(2);
+ java.sql.Timestamp ts = resultSet.getTimestamp(3);
+ String intervalYear = resultSet.getString(4);
+ String intervalDay = resultSet.getString(5);
+
+ System.out.println("Date: " + date.toString() + " time: " + time.toString() + " timestamp: " + ts.toString() +
+ "\ninterval year: " + intervalYear + " intervalDay: " + intervalDay);
+
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
+
@Test
public void testShowFiles() throws Exception {
testQuery("show files from dfs.`/tmp`");
[2/4] git commit: DRILL-604: Add schema type to
INFORMATION_SCHEMA.SCHEMATA.
Posted by ja...@apache.org.
DRILL-604: Add schema type to INFORMATION_SCHEMA.SCHEMATA.
Modification for SubSchemaWrapper.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/a4a02ef4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/a4a02ef4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/a4a02ef4
Branch: refs/heads/master
Commit: a4a02ef4733b31e03f7402e611e73252945953eb
Parents: e7a486d
Author: Jinfeng Ni <jn...@maprtech.com>
Authored: Mon May 12 16:03:47 2014 -0700
Committer: Aditya Kishore <ad...@maprtech.com>
Committed: Tue May 13 15:27:38 2014 -0700
----------------------------------------------------------------------
.../exec/store/hbase/HBaseSchemaFactory.java | 7 +++++++
.../store/hbase/HBaseStoragePluginConfig.java | 4 +++-
.../apache/drill/exec/store/AbstractSchema.java | 2 ++
.../drill/exec/store/SubSchemaWrapper.java | 5 +++++
.../drill/exec/store/dfs/FileSystemConfig.java | 4 ++--
.../exec/store/dfs/FileSystemSchemaFactory.java | 9 ++++++++-
.../exec/store/dfs/WorkspaceSchemaFactory.java | 9 ++++++++-
.../store/hive/HiveStoragePluginConfig.java | 5 ++++-
.../store/hive/schema/HiveDatabaseSchema.java | 10 +++++++++-
.../store/hive/schema/HiveSchemaFactory.java | 8 ++++++++
.../exec/store/ischema/InfoSchemaConfig.java | 8 +++++---
.../store/ischema/InfoSchemaStoragePlugin.java | 10 ++++++++--
.../exec/store/ischema/InfoSchemaTable.java | 21 ++++++++++----------
.../drill/exec/store/ischema/OptiqProvider.java | 3 ++-
.../store/mock/MockStorageEngineConfig.java | 6 ++++--
.../drill/exec/store/sys/SystemTablePlugin.java | 5 +++++
.../exec/store/sys/SystemTablePluginConfig.java | 2 +-
17 files changed, 92 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
index e175c1b..ce3b9fd 100644
--- a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
+++ b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
@@ -29,6 +29,7 @@ import org.apache.drill.exec.planner.logical.DynamicDrillTable;
import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.SchemaFactory;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -92,5 +93,11 @@ public class HBaseSchemaFactory implements SchemaFactory {
return Collections.emptySet();
}
}
+
+ @Override
+ public String getTypeName() {
+ return HBaseStoragePluginConfig.NAME;
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePluginConfig.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePluginConfig.java b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePluginConfig.java
index 054d65f..78630a9 100644
--- a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePluginConfig.java
+++ b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePluginConfig.java
@@ -32,7 +32,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-@JsonTypeName("hbase")
+@JsonTypeName(HBaseStoragePluginConfig.NAME)
public class HBaseStoragePluginConfig extends StoragePluginConfigBase implements DrillHBaseConstants {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HBaseStoragePluginConfig.class);
@@ -41,6 +41,8 @@ public class HBaseStoragePluginConfig extends StoragePluginConfigBase implements
@JsonIgnore
private Configuration hbaseConf;
+ public static final String NAME = "hbase";
+
@JsonCreator
public HBaseStoragePluginConfig(@JsonProperty("config") Map<String, String> props) {
this.config = props;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
index 485136b..f98d661 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
@@ -61,6 +61,8 @@ public abstract class AbstractSchema implements Schema{
return Joiner.on(".").join(schemaPath);
}
+ public abstract String getTypeName();
+
/**
* The schema can be a top level schema which doesn't have its own tables, but refers
* to one of the default sub schemas for table look up.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/SubSchemaWrapper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/SubSchemaWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/SubSchemaWrapper.java
index 576d761..dbfe93f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/SubSchemaWrapper.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/SubSchemaWrapper.java
@@ -84,4 +84,9 @@ public class SubSchemaWrapper extends AbstractSchema {
public Set<String> getTableNames() {
return innerSchema.getTableNames();
}
+
+ @Override
+ public String getTypeName() {
+ return innerSchema.getTypeName();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemConfig.java
index 2d1a9ba..48a8943 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemConfig.java
@@ -24,10 +24,10 @@ import org.apache.drill.common.logical.StoragePluginConfig;
import com.fasterxml.jackson.annotation.JsonTypeName;
-@JsonTypeName("file")
+@JsonTypeName(FileSystemConfig.NAME)
public class FileSystemConfig implements StoragePluginConfig{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FileSystemConfig.class);
-
+ public static final String NAME = "file";
public String connection;
public Map<String, WorkspaceConfig> workspaces;
public Map<String, FormatPluginConfig> formats;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
index 9a57aa2..5d291f9 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
@@ -23,11 +23,12 @@ import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableList;
+
import net.hydromatic.optiq.Function;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
-
import net.hydromatic.optiq.Table;
+
import org.apache.drill.exec.planner.logical.CreateTableEntry;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.rpc.user.DrillUser;
@@ -37,6 +38,7 @@ import org.apache.drill.exec.store.SchemaFactory;
import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory.WorkspaceSchema;
import com.google.common.collect.Maps;
+
import org.apache.drill.exec.store.dfs.shim.DrillFileSystem;
@@ -91,6 +93,11 @@ public class FileSystemSchemaFactory implements SchemaFactory{
}
@Override
+ public String getTypeName() {
+ return FileSystemConfig.NAME;
+ }
+
+ @Override
public Table getTable(String name) {
return defaultSchema.getTable(name);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
index 72b31e6..b17779b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
@@ -24,7 +24,9 @@ import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+
import net.hydromatic.optiq.Table;
+
import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.planner.logical.CreateTableEntry;
@@ -79,7 +81,7 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
FileSelection fileSelection = FileSelection.create(fs, config.getLocation(), key);
if(fileSelection == null) return null;
-
+
if (fileSelection.containsDirectories(fs)) {
for (FormatMatcher m : dirMatchers) {
try {
@@ -159,6 +161,11 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
formatPlugin,
config.getLocation() + Path.SEPARATOR + tableName);
}
+
+ @Override
+ public String getTypeName() {
+ return FileSystemConfig.NAME;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePluginConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePluginConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePluginConfig.java
index c9d76e5..cbd7906 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePluginConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePluginConfig.java
@@ -21,18 +21,21 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+
import org.apache.drill.common.logical.StoragePluginConfigBase;
import org.apache.hadoop.hive.conf.HiveConf;
import java.util.Map;
-@JsonTypeName("hive")
+@JsonTypeName(HiveStoragePluginConfig.NAME)
public class HiveStoragePluginConfig extends StoragePluginConfigBase {
@JsonProperty
public Map<String, String> configProps;
@JsonIgnore
private HiveConf hiveConf;
+ public static final String NAME = "hive";
+
@JsonIgnore
public HiveConf getHiveConf() {
if (hiveConf == null) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
index 4390d74..0df2374 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
@@ -21,8 +21,11 @@ import java.util.List;
import java.util.Set;
import net.hydromatic.optiq.Table;
+
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.store.AbstractSchema;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.hive.HiveStoragePluginConfig;
import org.apache.drill.exec.store.hive.schema.HiveSchemaFactory.HiveSchema;
import com.google.common.collect.Sets;
@@ -32,7 +35,7 @@ public class HiveDatabaseSchema extends AbstractSchema{
private final HiveSchema hiveSchema;
private final Set<String> tables;
-
+
public HiveDatabaseSchema( //
List<String> tableList, //
HiveSchema hiveSchema, //
@@ -52,4 +55,9 @@ public class HiveDatabaseSchema extends AbstractSchema{
return tables;
}
+ @Override
+ public String getTypeName() {
+ return HiveStoragePluginConfig.NAME;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
index 6dd6143..fb672d4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import com.google.common.collect.ImmutableList;
+
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
@@ -35,6 +36,7 @@ import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.SchemaFactory;
import org.apache.drill.exec.store.hive.HiveReadEntry;
import org.apache.drill.exec.store.hive.HiveStoragePlugin;
+import org.apache.drill.exec.store.hive.HiveStoragePluginConfig;
import org.apache.drill.exec.store.hive.HiveTable;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
@@ -273,6 +275,12 @@ public class HiveSchemaFactory implements SchemaFactory {
public AbstractSchema getDefaultSchema() {
return defaultSchema;
}
+
+ @Override
+ public String getTypeName() {
+ return HiveStoragePluginConfig.NAME;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaConfig.java
index d0ae77a..77bd254 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaConfig.java
@@ -21,15 +21,17 @@ import org.apache.drill.common.logical.StoragePluginConfig;
public class InfoSchemaConfig implements StoragePluginConfig{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(InfoSchemaConfig.class);
-
+
+ public static final String NAME = "ischema";
+
@Override
public int hashCode(){
return 1;
}
-
+
@Override
public boolean equals(Object o){
return o instanceof InfoSchemaConfig;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
index ecf5a8b..db91f08 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
@@ -23,9 +23,10 @@ import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableList;
-import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.Table;
+
import org.apache.drill.common.JSONOptions;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.StoragePluginConfig;
@@ -35,6 +36,7 @@ import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.AbstractStoragePlugin;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@@ -60,7 +62,7 @@ public class InfoSchemaStoragePlugin extends AbstractStoragePlugin{
@Override
public InfoSchemaGroupScan getPhysicalScan(JSONOptions selection, List<SchemaPath> columns) throws IOException {
SelectedTable table = selection.getWith(context.getConfig(), SelectedTable.class);
- return new InfoSchemaGroupScan(table, columns);
+ return new InfoSchemaGroupScan(table, columns);
}
@Override
@@ -95,5 +97,9 @@ public class InfoSchemaStoragePlugin extends AbstractStoragePlugin{
return tables.keySet();
}
+ @Override
+ public String getTypeName() {
+ return InfoSchemaConfig.NAME;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaTable.java
index 595488f..6ab41b0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaTable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaTable.java
@@ -39,8 +39,8 @@ public class InfoSchemaTable{
*/
public static class Schemata extends FixedTable {
static final String tableName = "SCHEMATA";
- static final String[] fieldNames = {"CATALOG_NAME", "SCHEMA_NAME", "SCHEMA_OWNER"};
- static final MajorType[] fieldTypes = {VARCHAR, VARCHAR, VARCHAR};
+ static final String[] fieldNames = {"CATALOG_NAME", "SCHEMA_NAME", "SCHEMA_OWNER", "TYPE"};
+ static final MajorType[] fieldTypes = {VARCHAR, VARCHAR, VARCHAR, VARCHAR};
public Schemata() {
super(tableName, fieldNames, fieldTypes);
@@ -48,10 +48,11 @@ public class InfoSchemaTable{
// Optional ...
public boolean writeRowToVectors(int index, Object[] row) {
- return
+ return
setSafe((VarCharVector)vectors.get(0), index, (String)row[0]) &&
setSafe((VarCharVector)vectors.get(1), index, (String)row[1]) &&
- setSafe((VarCharVector)vectors.get(2), index, (String)row[2]);
+ setSafe((VarCharVector)vectors.get(2), index, (String)row[2]) &&
+ setSafe((VarCharVector)vectors.get(3), index, (String)row[3]);
}
}
@@ -65,7 +66,7 @@ public class InfoSchemaTable{
public Tables() {
super(tableName, fieldNames, fieldTypes);
- }
+ }
// Optional ...
public boolean writeRowToVectors(int index, Object[] row) {
@@ -96,14 +97,14 @@ public class InfoSchemaTable{
// Optional ...
public boolean writeRowToVectors(int index, Object[] row) {
- return
+ return
setSafe((VarCharVector)vectors.get(0), index, (String)row[0]) &&
setSafe((VarCharVector)vectors.get(1), index, (String)row[1]) &&
setSafe((VarCharVector)vectors.get(2), index, (String)row[2]) &&
- setSafe((VarCharVector)vectors.get(3), index, (String)row[3]) &&
+ setSafe((VarCharVector)vectors.get(3), index, (String)row[3]) &&
setSafe((IntVector)vectors.get(4), index, (int)row[4]) &&
setSafe((VarCharVector)vectors.get(5), index, (String)row[5]) &&
- setSafe((VarCharVector)vectors.get(6), index, (String)row[6]) &&
+ setSafe((VarCharVector)vectors.get(6), index, (String)row[6]) &&
setSafe((IntVector)vectors.get(7), index, (int)row[7]) &&
setSafe((IntVector)vectors.get(8), index, (int)row[8]) &&
setSafe((IntVector)vectors.get(9), index, (int)row[9]) &&
@@ -146,6 +147,6 @@ public class InfoSchemaTable{
super(tableName, fieldNames, fieldTypes);
}
}
-
-
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/OptiqProvider.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/OptiqProvider.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/OptiqProvider.java
index e12e5d6..1aee579 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/OptiqProvider.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/OptiqProvider.java
@@ -61,7 +61,8 @@ public class OptiqProvider {
@Override
public boolean visitSchema(String schemaName, SchemaPlus schema) {
if (shouldVisitSchema(schema) && schemaName != null && schemaName != "") {
- writeRow("DRILL", schemaName, "<owner>");
+ AbstractSchema as = schema.unwrap(AbstractSchema.class);
+ writeRow("DRILL", schemaName, "<owner>", as.getTypeName());
}
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngineConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngineConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngineConfig.java
index 8262544..c566182 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngineConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngineConfig.java
@@ -23,13 +23,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-@JsonTypeName("mock")
+@JsonTypeName(MockStorageEngineConfig.NAME)
public class MockStorageEngineConfig extends StoragePluginConfigBase{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MockStorageEngineConfig.class);
private String url;
-
+
+ public static final String NAME = "mock";
+
@JsonCreator
public MockStorageEngineConfig(@JsonProperty("url") String url) {
this.url = url;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
index fd3a898..4abd253 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
@@ -115,5 +115,10 @@ public class SystemTablePlugin extends AbstractStoragePlugin{
}
+ @Override
+ public String getTypeName() {
+ return SystemTablePluginConfig.NAME;
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a4a02ef4/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePluginConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePluginConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePluginConfig.java
index bca9881..758368f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePluginConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePluginConfig.java
@@ -22,7 +22,7 @@ import org.apache.drill.common.logical.StoragePluginConfig;
public class SystemTablePluginConfig implements StoragePluginConfig{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SystemTablePluginConfig.class);
- String name = "system-tables";
+ public static String NAME = "system-tables";
public static SystemTablePluginConfig INSTANCE = new SystemTablePluginConfig();