You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2014/07/21 04:46:23 UTC
[01/17] git commit: DRILL-706,
DRILL-524 : div and mod funnc bugfix DRILL-706, 524,
988: Review Comments DRILL-706, 524, 988: Added Testcase
Repository: incubator-drill
Updated Branches:
refs/heads/master 699851b8d -> e5c2da0eb
DRILL-706, DRILL-524 : div and mod funnc bugfix DRILL-706,524,988: Review Comments DRILL-706,524,988: Added Testcase
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/1fb58403
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/1fb58403
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/1fb58403
Branch: refs/heads/master
Commit: 1fb5840313327930d01374a5a47b3734b8a70299
Parents: 785aa5a
Author: Yash Sharma <ya...@snapdeal.com>
Authored: Sat Jun 14 23:31:34 2014 +0530
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:26:35 2014 -0700
----------------------------------------------------------------------
.../src/main/codegen/data/MathFunc.tdd | 10 +++---
.../main/codegen/templates/MathFunctions.java | 20 +++++++++--
.../exec/fn/impl/TestNewMathFunctions.java | 13 +++----
.../functions/testDivModTruncFunctions.json | 38 ++++++++++++++++++++
4 files changed, 67 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/main/codegen/data/MathFunc.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/MathFunc.tdd b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
index cdce365..154836c 100644
--- a/exec/java-exec/src/main/codegen/data/MathFunc.tdd
+++ b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
@@ -85,12 +85,12 @@ unaryMathFunctions : [
{className: "Trunc", funcName: "trunc", types: [
{input: "Int", outputType: "Int", castType: "int"},
{input: "BigInt", outputType: "BigInt", castType: "long"},
- {input: "Float4", outputType: "Float4", castType: "float"},
- {input: "Float8", outputType: "Float8", castType: "double"},
+ {input: "Float4", outputType: "Float4", castType: "float", roundingRequired: "true"},
+ {input: "Float8", outputType: "Float8", castType: "double", roundingRequired: "true"},
{input: "SmallInt", outputType: "SmallInt", castType: "short"},
{input: "TinyInt", outputType: "TinyInt", castType: "byte"},
{input: "UInt1", outputType: "UInt1", castType: "byte"},
- {input: "UInt2", outputType: "UInt2", castType: "int", extraCast: "char"},
+ {input: "UInt2", outputType: "UInt2", castType: "char"},
{input: "UInt4", outputType: "UInt4", castType: "int"},
{input: "UInt8", outputType: "UInt8", castType: "long"}
]
@@ -113,8 +113,8 @@ unaryMathFunctions : [
{className: "Div", funcName: "div", javaFunc : " / ", types: [
{input: "Int", outputType: "Int", castType: "int"},
{input: "BigInt", outputType: "BigInt", castType: "long"},
- {input: "Float4", outputType: "Float4", castType: "float"},
- {input: "Float8", outputType: "Float8", castType: "double"},
+ {input: "Float4", outputType: "Float4", castType: "float", roundingRequired: "true"},
+ {input: "Float8", outputType: "Float8", castType: "double", roundingRequired: "true"},
{input: "SmallInt", outputType: "SmallInt", castType: "short"},
{input: "TinyInt", outputType: "TinyInt", castType: "byte"},
{input: "UInt1", outputType: "UInt1", castType: "byte"},
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/main/codegen/templates/MathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/MathFunctions.java b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
index 8986b8a..30a71dd 100644
--- a/exec/java-exec/src/main/codegen/templates/MathFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
@@ -69,10 +69,13 @@ public class GMathFunctions{
public void eval() {
<#if func.funcName=='trunc'>
- java.math.BigDecimal bd = new java.math.BigDecimal(String.valueOf(in.value)).setScale(0, java.math.BigDecimal.ROUND_DOWN);
+ <#if type.roundingRequired ??>
+ java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale(0, java.math.BigDecimal.ROUND_DOWN);
out.value = <#if type.extraCast ??>(${type.extraCast})</#if>bd.${type.castType}Value();
<#else>
- out.value =(${type.castType}) ${func.javaFunc}(in.value);
+ out.value = (${type.castType}) (in.value);</#if>
+ <#else>
+ out.value = (${type.castType}) ${func.javaFunc}(in.value);
</#if>
}
}
@@ -99,7 +102,18 @@ public class GMathFunctions{
}
public void eval() {
- out.value =(${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+ <#if func.funcName == 'div'>
+ <#if type.roundingRequired ??>
+ java.math.BigDecimal bdOut = java.math.BigDecimal.valueOf(input1.value ${func.javaFunc} input2.value).setScale(0, java.math.BigDecimal.ROUND_DOWN);
+ out.value = bdOut.${type.castType}Value();
+ <#else>
+ out.value = (${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+ </#if>
+ <#elseif func.funcName == 'mod'>
+ out.value = (${type.castType}) (input2.value == 0 ? input1.value : (input1.value ${func.javaFunc} input2.value));
+ <#else>
+ out.value =(${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+ </#if>
}
}
</#list>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
index 3289601..328dd9c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
@@ -35,7 +35,6 @@ import org.apache.drill.exec.physical.base.FragmentRoot;
import org.apache.drill.exec.physical.impl.ImplCreator;
import org.apache.drill.exec.physical.impl.OperatorCreatorRegistry;
import org.apache.drill.exec.physical.impl.SimpleRootExec;
-import org.apache.drill.exec.physical.impl.TestStringFunctions;
import org.apache.drill.exec.planner.PhysicalPlanReader;
import org.apache.drill.exec.proto.CoordinationProtos;
import org.apache.drill.exec.proto.BitControl.PlanFragment;
@@ -96,14 +95,9 @@ public class TestNewMathFunctions {
Object [] res = getRunResult(exec);
assertEquals("return count does not match", res.length, expectedResults.length);
- System.out.println("-----------------------------------------------");
- System.out.println("ACTUAL_RESULTS\t\tEXPECTED_RESULTS");
- System.out.println("-----------------------------------------------");
for (int i = 0; i<res.length; i++) {
- System.out.println(res[i] + "\t" + expectedResults[i]);
assertEquals(String.format("column %s does not match", i), res[i], expectedResults[i]);
}
- System.out.println("-----------------------------------------------");
}
if(context.getFailureCause() != null){
@@ -129,4 +123,11 @@ public class TestNewMathFunctions {
runTest(bitContext, connection, expected, "functions/testExtendedMathFunctions.json");
}
+
+ @Test
+ public void testTruncDivMod(@Injectable final DrillbitContext bitContext,
+ @Injectable UserServer.UserClientConnection connection) throws Throwable{
+ Object [] expected = new Object[] {101.0, 0, 101, 1010.0, 101, 481.0, 0.001099999999931267};
+ runTest(bitContext, connection, expected, "functions/testDivModTruncFunctions.json");
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json b/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
new file mode 100644
index 0000000..cf578c8
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
@@ -0,0 +1,38 @@
+{
+ head : {
+ version : 1,
+ generator : {
+ type : "optiq",
+ info : "na"
+ },
+ type : "APACHE_DRILL_PHYSICAL"
+ },
+ graph:[
+ {
+ @id:1,
+ pop:"mock-sub-scan",
+ url: "http://apache.org",
+ entries:[
+ {records: 1, types: [
+ {name: "blue", type: "BIGINT", mode: "REQUIRED"}
+ ]}
+ ]
+ }, {
+ pop : "project",
+ @id : 2,
+ exprs : [
+ { ref : "ref1", expr : " trunc(101.11) "},
+ { ref : "ref2", expr : " div(101, 111) "},
+ { ref : "ref3", expr : " mod(101, 111) " },
+ { ref : "ref4", expr : " trunc(1010.00) "},
+ { ref : "ref6", expr : " mod(101, 0) " },
+ { ref : "ref8", expr : " div(1010.1010, 2.1) "},
+ { ref : "ref9", expr : " mod(1010.10110, 2.1) " }
+ ],
+ child : 1
+ }, {
+ pop : "screen",
+ @id : 3,
+ child : 2
+ } ]
+}
\ No newline at end of file
[12/17] git commit: DRILL-77: REST API implemented using jersey and
jackson + graph viz.
Posted by ja...@apache.org.
DRILL-77: REST API implemented using jersey and jackson + graph viz.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/65c83582
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/65c83582
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/65c83582
Branch: refs/heads/master
Commit: 65c835824c864192cbd8612b14d08d816360d31e
Parents: 02f1c82
Author: Sudheesh Katkam <sk...@maprtech.com>
Authored: Tue Jul 8 17:23:57 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:33:39 2014 -0700
----------------------------------------------------------------------
.../drill/exec/server/rest/DrillRestServer.java | 1 +
.../exec/server/rest/PluginConfigWrapper.java | 78 +++++++
.../exec/server/rest/ProfileResources.java | 155 ++++++++-----
.../drill/exec/server/rest/QueryResources.java | 115 +++-------
.../drill/exec/server/rest/QueryWrapper.java | 165 ++++++++++++++
.../exec/server/rest/StorageResources.java | 228 +++++++++++--------
.../exec/server/rest/WebResourceServer.java | 71 ++++++
.../src/main/resources/rest/generic.ftl | 3 +-
.../src/main/resources/rest/metrics/metrics.ftl | 16 +-
.../src/main/resources/rest/profile/list.ftl | 63 ++---
.../src/main/resources/rest/profile/profile.ftl | 33 ++-
.../src/main/resources/rest/query/query.ftl | 6 +-
.../src/main/resources/rest/query/result.ftl | 32 ++-
.../src/main/resources/rest/storage/list.ftl | 84 ++++---
.../src/main/resources/rest/storage/update.ftl | 54 ++++-
.../src/main/resources/rest/www/graph.js | 82 +++++++
.../src/main/resources/rest/www/style.css | 27 +++
17 files changed, 867 insertions(+), 346 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRestServer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRestServer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRestServer.java
index cdbaaaf..ac6a537 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRestServer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRestServer.java
@@ -44,6 +44,7 @@ public class DrillRestServer extends ResourceConfig {
register(QueryResources.class);
register(MetricsResources.class);
register(ThreadsResources.class);
+ register(WebResourceServer.class);
register(FreemarkerMvcFeature.class);
property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true);
register(MultiPartFeature.class);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/PluginConfigWrapper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/PluginConfigWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/PluginConfigWrapper.java
new file mode 100644
index 0000000..003f8ae
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/PluginConfigWrapper.java
@@ -0,0 +1,78 @@
+/**
+ * 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.server.rest;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class PluginConfigWrapper {
+
+ private String name;
+ private StoragePluginConfig config;
+ private boolean exists;
+
+ @JsonCreator
+ public PluginConfigWrapper(@JsonProperty("name") String name, @JsonProperty("config") StoragePluginConfig config) {
+ this.name = name;
+ this.config = config;
+ this.exists = config != null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public StoragePluginConfig getConfig() {
+ return config;
+ }
+
+ public boolean enabled() {
+ return exists && config.isEnabled();
+ }
+
+ public void createOrUpdateInStorage(StoragePluginRegistry storage) throws ExecutionSetupException {
+ storage.createOrUpdate(name, config, true);
+ }
+
+ public boolean setEnabledInStorage(StoragePluginRegistry storage, boolean enabled) throws ExecutionSetupException {
+ if (exists) {
+ config.setEnabled(enabled);
+ createOrUpdateInStorage(storage);
+ }
+ return exists;
+ }
+
+ public boolean exists() {
+ return exists;
+ }
+
+ public boolean deleteFromStorage(StoragePluginRegistry storage) {
+ if (exists) {
+ storage.deletePlugin(name);
+ return true;
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/ProfileResources.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/ProfileResources.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/ProfileResources.java
index 7d29ea3..5ae4267 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/ProfileResources.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/ProfileResources.java
@@ -19,9 +19,8 @@ package org.apache.drill.exec.server.rest;
import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -32,6 +31,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import javax.xml.bind.annotation.XmlRootElement;
import org.apache.drill.exec.proto.UserBitShared.QueryProfile;
import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
@@ -42,82 +42,131 @@ import org.glassfish.jersey.server.mvc.Viewable;
import com.google.common.collect.Lists;
-@Path("/profiles")
+@Path("/")
public class ProfileResources {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ProfileResources.class);
@Inject WorkManager work;
+ public static class ProfileInfo implements Comparable<ProfileInfo> {
+ public static final SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
- @GET
- @Path("/{queryid}")
- @Produces(MediaType.TEXT_HTML)
- public Viewable getQuery(@PathParam("queryid") String queryId) throws IOException {
- PStore<QueryProfile> profiles = work.getContext().getPersistentStoreProvider().getPStore(QueryStatus.QUERY_PROFILE);
- QueryProfile profile = profiles.get(queryId);
- if(profile == null) profile = QueryProfile.getDefaultInstance();
+ private String queryId;
+ private Date time;
+ private String location;
- ProfileWrapper wrapper = new ProfileWrapper(profile);
+ public ProfileInfo(String queryId, long time) {
+ this.queryId = queryId;
+ this.time = new Date(time);
+ this.location = "http://localhost:8047/profile/" + queryId + ".json";
+ }
- return new Viewable("/rest/profile/profile.ftl", wrapper);
+ public String getQueryId() {
+ return queryId;
+ }
+
+ public String getTime() {
+ return format.format(time);
+ }
+
+ public String getLocation() {
+ return location;
+ }
+ @Override
+ public int compareTo(ProfileInfo other) {
+ return time.compareTo(other.time);
+ }
}
- @GET
- @Produces(MediaType.TEXT_HTML)
- public Viewable getResults() throws IOException {
- PStore<QueryProfile> profiles = work.getContext().getPersistentStoreProvider().getPStore(QueryStatus.QUERY_PROFILE);
-
- List<Map.Entry<String, Long>> runningIds = Lists.newArrayList();
- List<Map.Entry<String, Long>> finishedIds = Lists.newArrayList();
- for(Map.Entry<String, QueryProfile> entry : profiles){
- QueryProfile q = entry.getValue();
- if (q.getState() == QueryState.RUNNING || q.getState() == QueryState.PENDING) {
- runningIds.add(new AbstractMap.SimpleEntry<>(entry.getKey(), q.getStart()));
- } else {
- finishedIds.add(new AbstractMap.SimpleEntry<>(entry.getKey(), q.getStart()));
- }
+ @XmlRootElement
+ public class QProfiles {
+ private List<ProfileInfo> runningQueries;
+ private List<ProfileInfo> finishedQueries;
+
+ public QProfiles(List<ProfileInfo> runningQueries, List<ProfileInfo> finishedQueries) {
+ this.runningQueries = runningQueries;
+ this.finishedQueries = finishedQueries;
}
- Comparator<Map.Entry<String,Long>> comparator = new Comparator<Map.Entry<String,Long>>() {
- @Override
- public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
- return o2.getValue().compareTo(o1.getValue());
- }
- };
+ public List<ProfileInfo> getRunningQueries() {
+ return runningQueries;
+ }
- Collections.sort(runningIds, comparator);
- Collections.sort(finishedIds, comparator);
+ public List<ProfileInfo> getFinishedQueries() {
+ return finishedQueries;
+ }
+ }
- List<Map.Entry<String, String>> runningQueries = Lists.newArrayList();
- List<Map.Entry<String, String>> oldQueries = Lists.newArrayList();
- for(Map.Entry<String, Long> entry : runningIds){
- runningQueries.add(new AbstractMap.SimpleEntry<>(entry.getKey(), new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date(entry.getValue()))));
+ @GET
+ @Path("/profiles.json")
+ @Produces(MediaType.APPLICATION_JSON)
+ public QProfiles getProfilesJSON() {
+ PStore<QueryProfile> store = null;
+ try {
+ store = work.getContext().getPersistentStoreProvider().getPStore(QueryStatus.QUERY_PROFILE);
+ } catch (IOException e) {
+ logger.debug("Failed to get profiles from persistent store.");
+ return new QProfiles(new ArrayList<ProfileInfo>(), new ArrayList<ProfileInfo>());
}
- for(Map.Entry<String, Long> entry : finishedIds){
- oldQueries.add(new AbstractMap.SimpleEntry<>(entry.getKey(), new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date(entry.getValue()))));
+ List<ProfileInfo> runningQueries = Lists.newArrayList();
+ List<ProfileInfo> finishedQueries = Lists.newArrayList();
+
+ for(Map.Entry<String, QueryProfile> entry : store){
+ QueryProfile profile = entry.getValue();
+ if (profile.getState() == QueryState.RUNNING || profile.getState() == QueryState.PENDING) {
+ runningQueries.add(new ProfileInfo(entry.getKey(), profile.getStart()));
+ } else {
+ finishedQueries.add(new ProfileInfo(entry.getKey(), profile.getStart()));
+ }
}
- // add status (running, done)
- Queries queries = new Queries();
- queries.runningQueries = runningQueries;
- queries.oldQueries = oldQueries;
+ Collections.sort(runningQueries, Collections.reverseOrder());
+ Collections.sort(finishedQueries, Collections.reverseOrder());
- return new Viewable("/rest/profile/list.ftl", queries);
+ return new QProfiles(runningQueries, finishedQueries);
}
- public static class Queries {
- List<Map.Entry<String, String>> runningQueries;
- List<Map.Entry<String, String>> oldQueries;
+ @GET
+ @Path("/profiles")
+ @Produces(MediaType.TEXT_HTML)
+ public Viewable getProfiles() {
+ QProfiles profiles = getProfilesJSON();
+ return new Viewable("/rest/profile/list.ftl", profiles);
+ }
- public List<Map.Entry<String, String>> getRunningQueries() {
- return runningQueries;
+ private QueryProfile getQueryProfile(String queryId) {
+ PStore<QueryProfile> store = null;
+ try {
+ store = work.getContext().getPersistentStoreProvider().getPStore(QueryStatus.QUERY_PROFILE);
+ } catch (IOException e) {
+ logger.debug("Failed to get profile for: " + queryId);
+ return QueryProfile.getDefaultInstance();
}
+ QueryProfile profile = store.get(queryId);
+ return profile == null ? QueryProfile.getDefaultInstance() : profile;
+ }
- public List<Map.Entry<String, String>> getOldQueries() {
- return oldQueries;
+ @GET
+ @Path("/profiles/{queryid}.json")
+ @Produces(MediaType.APPLICATION_JSON)
+ public String getProfileJSON(@PathParam("queryid") String queryId) {
+ try {
+ return new String(QueryStatus.QUERY_PROFILE.getSerializer().serialize(getQueryProfile(queryId)));
+ } catch (IOException e) {
+ logger.debug("Failed to serialize profile for: " + queryId);
+ return ("{ 'message' : 'error (unable to serialize profile)' }");
}
}
-}
+ @GET
+ @Path("/profiles/{queryid}")
+ @Produces(MediaType.TEXT_HTML)
+ public Viewable getProfile(@PathParam("queryid") String queryId) {
+ ProfileWrapper wrapper = new ProfileWrapper(getQueryProfile(queryId));
+
+ return new Viewable("/rest/profile/profile.ftl", wrapper);
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
index 9c1dce1..8ad32b1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
@@ -17,10 +17,9 @@
*/
package org.apache.drill.exec.server.rest;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Map;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
@@ -30,24 +29,15 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import javax.xml.bind.annotation.XmlRootElement;
import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.coord.ClusterCoordinator;
-import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.proto.UserBitShared;
-import org.apache.drill.exec.record.RecordBatchLoader;
-import org.apache.drill.exec.record.VectorWrapper;
-import org.apache.drill.exec.rpc.RpcException;
-import org.apache.drill.exec.rpc.user.ConnectionThrottle;
-import org.apache.drill.exec.rpc.user.QueryResultBatch;
-import org.apache.drill.exec.rpc.user.UserResultsListener;
-import org.apache.drill.exec.vector.ValueVector;
import org.apache.drill.exec.work.WorkManager;
import org.glassfish.jersey.server.mvc.Viewable;
-@Path("/query")
+@Path("/")
public class QueryResources {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(QueryResources.class);
@@ -55,92 +45,55 @@ public class QueryResources {
WorkManager work;
@GET
+ @Path("/query")
@Produces(MediaType.TEXT_HTML)
public Viewable getQuery() {
return new Viewable("/rest/query/query.ftl");
}
@POST
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces(MediaType.TEXT_HTML)
- public Viewable submitQuery(@FormParam("query") String query, @FormParam("queryType") String queryType) throws Exception {
+ @Path("/query.json")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public List<Map<String, Object>> submitQueryJSON(QueryWrapper query) throws Exception {
final DrillConfig config = work.getContext().getConfig();
final ClusterCoordinator coordinator = work.getContext().getClusterCoordinator();
final BufferAllocator allocator = work.getContext().getAllocator();
- DrillClient client = new DrillClient(config, coordinator, allocator);
-
- UserBitShared.QueryType type = UserBitShared.QueryType.SQL;
- switch (queryType){
- case "SQL" : type = UserBitShared.QueryType.SQL; break;
- case "LOGICAL" : type = UserBitShared.QueryType.LOGICAL; break;
- case "PHYSICAL" : type = UserBitShared.QueryType.PHYSICAL; break;
- }
-
- client.connect();
- Listener listener = new Listener(new RecordBatchLoader(work.getContext().getAllocator()));
- client.runQuery(type, query, listener);
- List<LinkedList<String>> result = listener.waitForCompletion();
- client.close();
-
- return new Viewable("/rest/query/result.ftl", result);
+ return query.run(config, coordinator, allocator);
}
- private static class Listener implements UserResultsListener {
- private volatile Exception exception;
- private AtomicInteger count = new AtomicInteger();
- private CountDownLatch latch = new CountDownLatch(1);
- private LinkedList<LinkedList<String>> output = new LinkedList<>();
- private RecordBatchLoader loader;
+ @POST
+ @Path("/query")
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ @Produces(MediaType.TEXT_HTML)
+ public Viewable submitQuery(@FormParam("query") String query, @FormParam("queryType") String queryType) throws Exception {
+ List<Map<String, Object>> result = submitQueryJSON(new QueryWrapper(query, queryType));
- Listener(RecordBatchLoader loader) {
- this.loader = loader;
+ List<String> columnNames = new ArrayList<>(result.get(0).keySet());
+ List<List<Object>> records = new ArrayList<>();
+ for(Map m : result) {
+ records.add(new ArrayList<Object>(m.values()));
}
+ Table table = new Table(columnNames, records);
- @Override
- public void submissionFailed(RpcException ex) {
- exception = ex;
- System.out.println("Query failed: " + ex.getMessage());
- latch.countDown();
- }
+ return new Viewable("/rest/query/result.ftl", table);
+ }
+
+ public class Table {
+ private List<String> columnNames;
+ private List<List<Object>> records;
- @Override
- public void resultArrived(QueryResultBatch result, ConnectionThrottle throttle) {
- int rows = result.getHeader().getRowCount();
- if (result.getData() != null) {
- count.addAndGet(rows);
- try {
- loader.load(result.getHeader().getDef(), result.getData());
- output.add(new LinkedList<String>());
- for (int i = 0; i < loader.getSchema().getFieldCount(); ++i) {
- output.getLast().add(loader.getSchema().getColumn(i).getPath().getAsUnescapedPath());
- }
- } catch (SchemaChangeException e) {
- throw new RuntimeException(e);
- }
- for (int i = 0; i < rows; ++i) {
- output.add(new LinkedList<String>());
- for (VectorWrapper<?> vw : loader) {
- ValueVector.Accessor accessor = vw.getValueVector().getAccessor();
- output.getLast().add(accessor.getObject(i).toString());
- }
- }
- }
- result.release();
- if (result.getHeader().getIsLastChunk()) {
- latch.countDown();
- }
+ public Table(List<String> columnNames, List<List<Object>> records) {
+ this.columnNames = columnNames;
+ this.records = records;
}
- @Override
- public void queryIdArrived(UserBitShared.QueryId queryId) {
+ public List<String> getColumnNames() {
+ return columnNames;
}
- public List<LinkedList<String>> waitForCompletion() throws Exception {
- latch.await();
- if (exception != null) {
- throw exception;
- }
- return output;
+ public List<List<Object>> getRecords() {
+ return records;
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
new file mode 100644
index 0000000..83c82db
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
@@ -0,0 +1,165 @@
+/**
+ * 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.server.rest;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.coord.ClusterCoordinator;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.rpc.user.ConnectionThrottle;
+import org.apache.drill.exec.rpc.user.QueryResultBatch;
+import org.apache.drill.exec.rpc.user.UserResultsListener;
+import org.apache.drill.exec.vector.ValueVector;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@XmlRootElement
+public class QueryWrapper {
+
+ private String query;
+ private String queryType;
+
+ @JsonCreator
+ public QueryWrapper(@JsonProperty("query") String query, @JsonProperty("queryType") String queryType) {
+ this.query = query;
+ this.queryType = queryType;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getQueryType() {
+ return queryType;
+ }
+
+ public UserBitShared.QueryType getType() {
+ UserBitShared.QueryType type = UserBitShared.QueryType.SQL;
+ switch (queryType) {
+ case "SQL" : type = UserBitShared.QueryType.SQL; break;
+ case "LOGICAL" : type = UserBitShared.QueryType.LOGICAL; break;
+ case "PHYSICAL" : type = UserBitShared.QueryType.PHYSICAL; break;
+ }
+ return type;
+ }
+
+ public List<Map<String, Object>> run(DrillConfig config, ClusterCoordinator coordinator, BufferAllocator allocator)
+ throws Exception {
+ DrillClient client = new DrillClient(config, coordinator, allocator);
+ Listener listener = new Listener(new RecordBatchLoader(allocator));
+
+ client.connect();
+ client.runQuery(getType(), query, listener);
+
+ List<Map<String, Object>> result = listener.waitForCompletion();
+ client.close();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "QueryRequest [queryType=" + queryType + ", query=" + query + "]";
+ }
+
+
+ private static class Listener implements UserResultsListener {
+ private volatile Exception exception;
+ private AtomicInteger count = new AtomicInteger();
+ private CountDownLatch latch = new CountDownLatch(1);
+ private List<Map<String, Object>> output = new LinkedList<>();
+ private ArrayList<String> columnNames;
+ private RecordBatchLoader loader;
+ private boolean schemaAdded = false;
+
+ Listener(RecordBatchLoader loader) {
+ this.loader = loader;
+ }
+
+ @Override
+ public void submissionFailed(RpcException ex) {
+ exception = ex;
+ System.out.println("Query failed: " + ex.getMessage());
+ latch.countDown();
+ }
+
+ @Override
+ public void resultArrived(QueryResultBatch result, ConnectionThrottle throttle) {
+ int rows = result.getHeader().getRowCount();
+ if (result.getData() != null) {
+ count.addAndGet(rows);
+ try {
+ loader.load(result.getHeader().getDef(), result.getData());
+ if (!schemaAdded) {
+ columnNames = new ArrayList<>();
+ for (int i = 0; i < loader.getSchema().getFieldCount(); ++i) {
+ columnNames.add(loader.getSchema().getColumn(i).getPath().getAsUnescapedPath());
+ }
+ schemaAdded = true;
+ }
+ } catch (SchemaChangeException e) {
+ throw new RuntimeException(e);
+ }
+ for (int i = 0; i < rows; ++i) {
+ Map<String, Object> record = new HashMap<>();
+ int j = 0;
+ for (VectorWrapper<?> vw : loader) {
+ ValueVector.Accessor accessor = vw.getValueVector().getAccessor();
+ Object object = accessor.getObject(i);
+ if (! object.getClass().getName().startsWith("java.lang")) {
+ object = object.toString();
+ }
+ record.put(columnNames.get(j), object);
+ ++j;
+ }
+ output.add(record);
+ }
+ }
+ result.release();
+ if (result.getHeader().getIsLastChunk()) {
+ latch.countDown();
+ }
+ }
+
+ @Override
+ public void queryIdArrived(UserBitShared.QueryId queryId) {
+ }
+
+ public List<Map<String, Object>> waitForCompletion() throws Exception {
+ latch.await();
+ if (exception != null) {
+ throw exception;
+ }
+ return output;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
index 714e711..e841430 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
@@ -17,160 +17,186 @@
*/
package org.apache.drill.exec.server.rest;
-import java.io.IOException;
-import java.io.StringReader;
-import java.net.URI;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.exec.store.StoragePlugin;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.sys.PStoreProvider;
+import org.glassfish.jersey.server.mvc.Viewable;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.drill.common.exceptions.ExecutionSetupException;
-import org.apache.drill.common.logical.StoragePluginConfig;
-import org.apache.drill.exec.store.StoragePlugin;
-import org.apache.drill.exec.store.StoragePluginRegistry;
-import org.apache.drill.exec.store.sys.PStoreProvider;
-import org.glassfish.jersey.server.mvc.Viewable;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.Lists;
-
-import freemarker.template.SimpleHash;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
-@Path("/storage")
+@Path("/")
public class StorageResources {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StorageResources.class);
-
- static final Comparator<Pair<String, Boolean>> PLUGIN_NAME_COMPARATOR = new Comparator<Pair<String, Boolean>>() {
+
+ @Inject
+ StoragePluginRegistry storage;
+// @Inject
+// PStoreProvider storeProvider;
+ @Inject
+ ObjectMapper mapper;
+
+ static final Comparator<PluginConfigWrapper> PLUGIN_COMPARATOR = new Comparator<PluginConfigWrapper>() {
@Override
- public int compare(Pair<String, Boolean> o1, Pair<String, Boolean> o2) {
- return o1.getKey().compareTo(o2.getKey());
+ public int compare(PluginConfigWrapper o1, PluginConfigWrapper o2) {
+ return o1.getName().compareTo(o2.getName());
}
};
- @Inject StoragePluginRegistry storage;
- @Inject PStoreProvider storeProvider;
- @Inject ObjectMapper mapper;
-
@GET
- @Produces(MediaType.TEXT_HTML)
- public Viewable listPlugins() {
- // build a list and sort by plugin instance name
- List<Pair<String, Boolean>> pluginList = Lists.newArrayList();
- for (Map.Entry<String, StoragePluginConfig> config : storage.getStore()) {
- pluginList.add(ImmutablePair.of(config.getKey(), config.getValue().isEnabled()));
- }
- Collections.sort(pluginList, PLUGIN_NAME_COMPARATOR);
-
- // now use the sorted list to build the freemarker model
- List<SimpleHash> modelList = Lists.newArrayList();
- for (Pair<String, Boolean> plugin : pluginList) {
- SimpleHash map = new SimpleHash();
- map.put("name", plugin.getLeft());
- map.put("enabled", plugin.getRight());
- modelList.add(map);
+ @Path("/storage.json")
+ @Produces(MediaType.APPLICATION_JSON)
+ public List<PluginConfigWrapper> getStoragePluginsJSON() {
+
+ List<PluginConfigWrapper> list = Lists.newArrayList();
+ for (Map.Entry<String, StoragePluginConfig> entry : storage.getStore()) {
+ PluginConfigWrapper plugin = new PluginConfigWrapper(entry.getKey(), entry.getValue());
+ list.add(plugin);
}
- return new Viewable("/rest/storage/list.ftl", modelList);
+ Collections.sort(list, PLUGIN_COMPARATOR);
+
+ return list;
}
@GET
- @Path("/{name}/config/update")
+ @Path("/storage")
@Produces(MediaType.TEXT_HTML)
- public Viewable update(@PathParam("name") String name) throws JsonProcessingException {
- StoragePluginConfig config = findConfig(name);
- String conf = config == null ? "" : mapper.writeValueAsString(config);
-
- SimpleHash map = new SimpleHash();
- map.put("config", conf);
- map.put("name", name);
- map.put("exists", config != null);
- map.put("enabled", config != null && config.isEnabled());
- return new Viewable("/rest/storage/update.ftl", map);
+ public Viewable getStoragePlugins() {
+ List<PluginConfigWrapper> list = getStoragePluginsJSON();
+ return new Viewable("/rest/storage/list.ftl", list);
}
@GET
- @Path("/{name}/config/enable/{val}")
- @Produces(MediaType.TEXT_HTML)
- public Response setEnable(@Context UriInfo uriInfo, @PathParam("name") String name, @PathParam("val") Boolean enable) throws ExecutionSetupException {
- StoragePluginConfig config = findConfig(name);
- if (config != null) {
- config.setEnabled(enable);
- storage.createOrUpdate(name, config, true);
+ @Path("/storage/{name}.json")
+ @Produces(MediaType.APPLICATION_JSON)
+ public PluginConfigWrapper getStoragePluginJSON(@PathParam("name") String name) {
+ try {
+ StoragePlugin plugin = storage.getPlugin(name);
+ if (plugin != null) {
+ return new PluginConfigWrapper(name, plugin.getConfig());
+ }
+ } catch (Exception e) {
+ logger.info("Failure while trying to access storage config: {}", name, e);
}
-
- URI uri = uriInfo.getBaseUriBuilder().path("/storage").build();
- return Response.seeOther(uri).build();
+ return new PluginConfigWrapper(name, null);
}
@GET
- @Path("/{name}/config/delete")
+ @Path("/storage/{name}")
@Produces(MediaType.TEXT_HTML)
- public Viewable deleteConfig(@PathParam("name") String name) {
- storage.deletePlugin(name);
- return new Viewable("/rest/status.ftl", "Deleted " + name);
+ public Viewable getStoragePlugin(@PathParam("name") String name) {
+ PluginConfigWrapper plugin = getStoragePluginJSON(name);
+ return new Viewable("/rest/storage/update.ftl", plugin);
+ }
+
+ @GET
+ @Path("/storage/{name}/enable/{val}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public JsonResult enablePlugin(@PathParam("name") String name, @PathParam("val") Boolean enable) {
+ PluginConfigWrapper plugin = getStoragePluginJSON(name);
+ try {
+ if (plugin.setEnabledInStorage(storage, enable)) {
+ return message("success");
+ } else {
+ return message("error (plugin does not exist)");
+ }
+ } catch (ExecutionSetupException e) {
+ logger.debug("Error in enabling storage name: " + name + " flag: " + enable);
+ return message("error (unable to enable/ disable storage)");
+ }
+ }
+
+ @DELETE
+ @Path("/storage/{name}.json")
+ @Produces(MediaType.APPLICATION_JSON)
+ public JsonResult deletePluginJSON(@PathParam("name") String name) {
+ PluginConfigWrapper plugin = getStoragePluginJSON(name);
+ if (plugin.deleteFromStorage(storage)) {
+ return message("success");
+ } else {
+ return message("error (unable to delete storage)");
+ }
}
@GET
+ @Path("/storage/{name}/delete")
@Produces(MediaType.APPLICATION_JSON)
- @Path("/{name}/config")
- public StoragePluginConfig getConfig(@PathParam("name") String name) {
- return findConfig(name);
+ public JsonResult deletePlugin(@PathParam("name") String name) {
+ return deletePluginJSON(name);
}
- private StoragePluginConfig findConfig(String name) {
+ @POST
+ @Path("/storage/{name}.json")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public JsonResult createOrUpdatePluginJSON(PluginConfigWrapper plugin) {
try {
- StoragePlugin plugin = storage.getPlugin(name);
- if (plugin != null) {
- return plugin.getConfig();
- }
- } catch (Exception e) {
- logger.info("Failure while trying to access storage config: {}", name, e);
- ;
+ plugin.createOrUpdateInStorage(storage);
+ return message("success");
+ } catch (ExecutionSetupException e) {
+ logger.debug("Unable to create/ update plugin: " + plugin.getName());
+ return message("error (unable to create/ update storage)");
}
- return null;
}
@POST
- @Path("/config/update")
- @Produces(MediaType.TEXT_HTML)
+ @Path("/storage/{name}")
@Consumes("application/x-www-form-urlencoded")
- public Viewable createTrackInJSON(@FormParam("name") String name, @FormParam("config") String storagePluginConfig)
- throws ExecutionSetupException, JsonParseException, JsonMappingException, IOException {
- StoragePluginConfig config = mapper.readValue(new StringReader(storagePluginConfig), StoragePluginConfig.class);
- storage.createOrUpdate(name, config, true);
- return new Viewable("/rest/status.ftl", "Updated " + name);
+ @Produces(MediaType.APPLICATION_JSON)
+ public JsonResult createOrUpdatePlugin(@FormParam("name") String name, @FormParam("config") String storagePluginConfig) {
+ try {
+ StoragePluginConfig config = mapper.readValue(new StringReader(storagePluginConfig), StoragePluginConfig.class);
+ return createOrUpdatePluginJSON(new PluginConfigWrapper(name, config));
+ } catch (JsonMappingException e) {
+ logger.debug("Error in JSON mapping: " + storagePluginConfig);
+ return message("error (invalid JSON mapping)");
+ } catch (JsonParseException e) {
+ logger.debug("Error parsing JSON: " + storagePluginConfig);
+ return message("error (unable to parse JSON)");
+ } catch (IOException e) {
+ logger.debug("Failed to read: " + storagePluginConfig);
+ return message("error (unable to read)");
+ }
}
- private JsonResult r(String message) {
+ private JsonResult message(String message) {
return new JsonResult(message);
}
- public static class JsonResult {
- public String result = "data updated";
+ @XmlRootElement
+ public class JsonResult {
+
+ private String result;
public JsonResult(String result) {
- super();
this.result = result;
}
+ public String getResult() {
+ return result;
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebResourceServer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebResourceServer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebResourceServer.java
new file mode 100644
index 0000000..33b9be9
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebResourceServer.java
@@ -0,0 +1,71 @@
+/**
+ * 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.server.rest;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLConnection;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.drill.exec.work.WorkManager;
+
+@Path("/www")
+public class WebResourceServer {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(WebResourceServer.class);
+
+ @Inject WorkManager work;
+
+
+ @GET
+ @Path("/{path}")
+ @Produces(MediaType.TEXT_PLAIN)
+ public Response getResource(@PathParam("path") String path) throws IOException {
+ try {
+ String s = "rest/www/" + path;
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = new BufferedInputStream(cl.getResource(s).openStream());
+
+ String mime = "text/plain";
+ if (s.endsWith(".js")) {
+ mime = "text/javascript";
+ } else if (s.endsWith(".css")) {
+ mime = "text/css";
+ } else {
+ mime = URLConnection.guessContentTypeFromStream(is);
+ }
+
+ byte[] d = IOUtils.toByteArray(is);
+ return Response.ok(d).type(mime).build();
+ } catch (Exception e) {
+ e.printStackTrace();
+ e.printStackTrace(System.out);
+ }
+
+ return Response.noContent().status(Status.NOT_FOUND).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/generic.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/generic.ftl b/exec/java-exec/src/main/resources/rest/generic.ftl
index 256d582..1cbfc23 100644
--- a/exec/java-exec/src/main/resources/rest/generic.ftl
+++ b/exec/java-exec/src/main/resources/rest/generic.ftl
@@ -49,11 +49,10 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
- <a class="navbar-brand" href="/">Apache Drill</a>
+ <a class="navbar-brand">Apache Drill</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
- <li><a href="/status">Status</a></li>
<li><a href="/query">Query</a></li>
<li><a href="/profiles">Profiles</a></li>
<li><a href="/storage">Storage</a></li>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl b/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
index b0ccde8..1600a2d 100644
--- a/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
+++ b/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
@@ -60,7 +60,7 @@
<h3 id="histograms">Histograms</h3>
<div id="histogramsVal">
<div class="alert alert-info">
- <strong>No counters.</strong>
+ <strong>No histograms.</strong>
</div>
</div>
<h3 id="meters">Meters</h3>
@@ -114,13 +114,12 @@
});
};
- function updateTimers(timers) {
- console.log("yup");
- $("#timersVal").html(function() {
+ function createTable(metric, name) {
+ $("#" + name + "Val").html(function() {
var tables = "";
- $.each(timers, function(name, stats) {
+ $.each(metric, function(clazz, stats) {
- var table = "<strong>Reporting class:</strong> " + name + "<br>";
+ var table = "<strong>Reporting class:</strong> " + clazz + "<br>";
table += "<table class=\"table table-striped\"><tbody>";
$.each(stats, function(key, value) {
table += "<tr>";
@@ -140,7 +139,7 @@
};
function updateOthers(metrics) {
- $.each(["counters", "histograms", "meters"], function(i, key) {
+ $.each(["counters", "meters"], function(i, key) {
if(! $.isEmptyObject(metrics[key])) {
$("#" + key + "Val").html(JSON.stringify(metrics[key], null, 2));
}
@@ -151,7 +150,8 @@
$.get("/status/metrics", function(metrics) {
updateGauges(metrics.gauges);
updateBars(metrics.gauges);
- if(! $.isEmptyObject(metrics.timers)) updateTimers(metrics.timers);
+ if(! $.isEmptyObject(metrics.timers)) createTable(metrics.timers, "timers");
+ if(! $.isEmptyObject(metrics.histograms)) createTable(metrics.histograms, "histograms");
updateOthers(metrics);
});
};
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/profile/list.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/profile/list.ftl b/exec/java-exec/src/main/resources/rest/profile/list.ftl
index 61d3466..76f9a07 100644
--- a/exec/java-exec/src/main/resources/rest/profile/list.ftl
+++ b/exec/java-exec/src/main/resources/rest/profile/list.ftl
@@ -17,29 +17,38 @@
<a href="/queries">back</a><br/>
<div class="page-header">
</div>
- <h3>Running Queries</h3>
- <div class="table-responsive">
- <table class="table table-hover">
- <thead>
- <td>Time</td>
- <td>Query</td>
- </thead>
- <tbody>
- <#list model.getRunningQueries() as query>
- <tr>
- <td>${query.getValue()}</td>
- <td>
- <a href="/profiles/${query.getKey()}">
- <div style="height:100%;width:100%">
- ${query.getKey()}
- </div>
- </a>
- </td>
- </tr>
- </#list>
- </tbody>
- </table>
- </div>
+ <#if (model.getRunningQueries()?size > 0) >
+ <h3>Running Queries</h3>
+ <div class="table-responsive">
+ <table class="table table-hover">
+ <thead>
+ <td>Time</td>
+ <td>Query</td>
+ </thead>
+ <tbody>
+ <#list model.getRunningQueries() as query>
+ <tr>
+ <td>${query.getTime()}</td>
+ <td>
+ <a href="/profiles/${query.getQueryId()}">
+ <div style="height:100%;width:100%">
+ ${query.getQueryId()}
+ </div>
+ </a>
+ </td>
+ </tr>
+ </#list>
+ </tbody>
+ </table>
+ </div>
+ <div class="page-header">
+ </div>
+ <#else>
+ <div id="message" class="alert alert-info alert-dismissable">
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+ <strong>No running queries.</strong>
+ </div>
+ </#if>
<h3>Completed Queries</h3>
<div class="table-responsive">
<table class="table table-hover">
@@ -48,13 +57,13 @@
<td>Query</td>
</thead>
<tbody>
- <#list model.getOldQueries() as query>
+ <#list model.getFinishedQueries() as query>
<tr>
- <td>${query.getValue()}</td>
+ <td>${query.getTime()}</td>
<td>
- <a href="/profiles/${query.getKey()}">
+ <a href="/profiles/${query.getQueryId()}">
<div style="height:100%;width:100%">
- ${query.getKey()}
+ ${query.getQueryId()}
</div>
</a>
</td>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/profile/profile.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/profile/profile.ftl b/exec/java-exec/src/main/resources/rest/profile/profile.ftl
index 94b8aa1..8abb316 100644
--- a/exec/java-exec/src/main/resources/rest/profile/profile.ftl
+++ b/exec/java-exec/src/main/resources/rest/profile/profile.ftl
@@ -11,16 +11,21 @@
<#include "*/generic.ftl">
<#macro page_head>
+<link href="/www/style.css" rel="stylesheet">
+
+<script src="http://d3js.org/d3.v3.min.js"></script>
+<script src="http://cpettitt.github.io/project/dagre-d3/latest/dagre-d3.js"></script>
+<script src="/www/graph.js"></script>
</#macro>
<#macro page_body>
<a href="/queries">back</a><br/>
<div class="page-header">
</div>
- <h2>Query</h2>
+ <h3>Query</h3>
<form role="form" action="/query" method="POST">
<div class="form-group">
- <textarea class="form-control" id="query" name="query">${model.getProfile().query}</textarea>
+ <textarea class="form-control" id="query" name="query" style="font-family: Courier;">${model.getProfile().query}</textarea>
</div>
<div class="form-group">
<div class="radio-inline">
@@ -45,17 +50,29 @@
<button type="submit" class="btn btn-default">Re-run query</button>
</form>
<div class="page-header">
- <h2>Physical Plan</h2>
</div>
- <p><pre>${model.profile.plan}</pre></p>
+ <h3>Visualized Plan</h3>
+ <button id="renderbutton" class="btn btn-default">Generate</button>
+ <svg id="svg-canvas" style="margin: auto; display: block;">
+ <g transform="translate(20, 20)"/>
+ </svg>
+ <div class="page-header">
+ </div>
+ <h3>Physical Plan</h3>
+ <p><pre>${model.profile.plan}</pre></p>
<div class="page-header">
- <h2>Profile Summary</h2>
</div>
- <p>${model.toString()}</p>
+ <h3>Profile Summary</h3>
+ <p>${model.toString()}</p>
<div class="page-header">
- <h2>Complete Profile</h2>
</div>
- <p><pre>${model.profile.toString()}</pre></p>
+ <div class="span4 collapse-group">
+ <a class="btn btn-default" data-toggle="collapse" data-target="#viewdetails">View complete profile</a>
+ <br> <br>
+ <pre class="collapse" id="viewdetails">${model.profile.toString()}</pre>
+ </div>
+ <div class="page-header">
+ </div> <br>
</#macro>
<@page_html/>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/query/query.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/query/query.ftl b/exec/java-exec/src/main/resources/rest/query/query.ftl
index 32e18de..5033aca 100644
--- a/exec/java-exec/src/main/resources/rest/query/query.ftl
+++ b/exec/java-exec/src/main/resources/rest/query/query.ftl
@@ -17,6 +17,10 @@
<a href="/queries">back</a><br/>
<div class="page-header">
</div>
+ <div id="message" class="alert alert-info alert-dismissable" style="font-family: Courier;">
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+ Sample SQL query: <strong>SELECT * FROM cp.`employee.json` LIMIT 20</strong>
+ </div>
<form role="form" action="/query" method="POST">
<div class="form-group">
<label for="queryType">Query Type</label>
@@ -41,7 +45,7 @@
</div>
<div class="form-group">
<label for="query">Query</label>
- <textarea class="form-control" id="query" rows="5" name="query"></textarea>
+ <textarea class="form-control" id="query" rows="5" name="query" style="font-family: Courier;"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/query/result.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/query/result.ftl b/exec/java-exec/src/main/resources/rest/query/result.ftl
index a3cb0ce..0d60da8 100644
--- a/exec/java-exec/src/main/resources/rest/query/result.ftl
+++ b/exec/java-exec/src/main/resources/rest/query/result.ftl
@@ -15,8 +15,7 @@
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/be7019ee387/integration/jqueryui/dataTables.jqueryui.css">
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
- <script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.min.js"></script>
- <script type="text/javascript" language="javascript" src="//cdn.datatables.net/plug-ins/be7019ee387/integration/jqueryui/dataTables.jqueryui.js"></script>
+ <script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/colvis/1.1.0/css/dataTables.colVis.css">
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/colvis/1.1.0/js/dataTables.colVis.min.js"></script>
@@ -26,35 +25,32 @@
<a href="/queries">back</a><br/>
<div class="page-header">
</div>
- <h2>Result</h2>
- <div style="width=100%; overflow: auto;">
- <table id="relation" class="table table-striped table-bordered table-condensed" style="table-layout: auto; width=100%;">
- <#assign rows = model[0]>
+ <div>
+ <table id="result" class="table table-striped table-bordered table-condensed" style="table-layout: auto; width=100%;">
<thead>
<tr>
- <#list rows as row>
- <th>${row}</th>
+ <#list model.getColumnNames() as value>
+ <th>${value}</th>
</#list>
</tr>
</thead>
<tbody>
- <#list model as rows>
- <#if (rows_index > 0)>
- <tr>
- <#list rows as row>
- <td>${row}</td>
- </#list>
- </tr>
- </#if>
+ <#list model.getRecords() as record>
+ <tr>
+ <#list record as value>
+ <td>${value}</td>
+ </#list>
+ </tr>
</#list>
</tbody>
</table>
</div>
<script charset="utf-8">
$(document).ready(function() {
- $('#relation').dataTable( {
+ $('#result').dataTable( {
"scrollX" : true,
- "dom": '<Clfrtip>'
+ "dom": '<"H"lCfr>t<"F"ip>',
+ "jQueryUI" : true
} );
} );
</script>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/storage/list.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/storage/list.ftl b/exec/java-exec/src/main/resources/rest/storage/list.ftl
index 226bd2b..ef97561 100644
--- a/exec/java-exec/src/main/resources/rest/storage/list.ftl
+++ b/exec/java-exec/src/main/resources/rest/storage/list.ftl
@@ -17,58 +17,72 @@
<a href="/queries">back</a><br/>
<div class="page-header">
</div>
- <h3>Registered Storage Plugins</h3>
+ <h4>Enabled Storage Plugins</h4>
<div class="table-responsive">
<table class="table">
<tbody>
- <tr><th colspan="2" style="border:none;">Enabled Plugins</th></tr>
<#list model as plugin>
- <#if plugin.enabled == true>
- <tr>
- <td style="border:none;">
- ${plugin.name}
- </td>
- <td style="border:none;">
- <a class="btn btn-default" href="/storage/${plugin.name}/config/update">Update</a>
- <a class="btn btn-default" href="/storage/${plugin.name}/config/enable/false">Disable</a>
- </td>
- </tr>
- </#if>
+ <#if plugin.enabled() == true>
+ <tr>
+ <td style="border:none; width:200px;">
+ ${plugin.getName()}
+ </td>
+ <td style="border:none;">
+ <a class="btn btn-primary" href="/storage/${plugin.getName()}">Update</a>
+ <a class="btn btn-default" onclick="doEnable('${plugin.getName()}', false)">Disable</a>
+ </td>
+ </tr>
+ </#if>
</#list>
- <tr><th colspan="2" style="border:none;">Disabled Plugins</th></tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="page-header">
+ </div>
+ <h4>Disabled Storage Plugins</h4>
+ <div class="table-responsive">
+ <table class="table">
+ <tbody>
<#list model as plugin>
- <#if plugin.enabled == false>
- <tr>
- <td style="border:none;">
- ${plugin.name}
- </td>
- <td style="border:none;">
- <a class="btn btn-default" href="/storage/${plugin.name}/config/update">Update</a>
- <a class="btn btn-default" href="/storage/${plugin.name}/config/enable/true">Enable</a>
- </td>
- </tr>
- </#if>
+ <#if plugin.enabled() == false>
+ <tr>
+ <td style="border:none; width:200px;">
+ ${plugin.getName()}
+ </td>
+ <td style="border:none;">
+ <a class="btn btn-primary" href="/storage/${plugin.getName()}">Update</a>
+ <a class="btn btn-primary" onclick="doEnable('${plugin.getName()}', true)">Enable</a>
+ </td>
+ </tr>
+ </#if>
</#list>
</tbody>
</table>
</div>
+ <div class="page-header">
+ </div>
<div>
- <h4>Create new storage configuration</h4>
+ <h4>New Storage Plugin</h4>
<form class="form-inline" id="newStorage" role="form" action="/" method="GET">
<div class="form-group">
<input type="text" class="form-control" id="storageName" placeholder="Storage Name">
</div>
- <script>
- function doSubmit() {
- var name = document.getElementById("storageName");
- var form = document.getElementById("newStorage");
- form.action = "/storage/" + name.value + "/config/update";
- form.submit();
- }
- </script>
- <button type="submit" class="btn btn-default" onclick="javascript:doSubmit();">Create</button>
+ <button type="submit" class="btn btn-default" onclick="doSubmit()">Create</button>
</form>
</div>
+ <script>
+ function doSubmit() {
+ var name = document.getElementById("storageName");
+ var form = document.getElementById("newStorage");
+ form.action = "/storage/" + name.value;
+ form.submit();
+ };
+ function doEnable(name, flag) {
+ $.get("/storage/" + name + "/enable/" + flag, function(data) {
+ location.reload();
+ });
+ };
+ </script>
</#macro>
<@page_html/>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/storage/update.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/storage/update.ftl b/exec/java-exec/src/main/resources/rest/storage/update.ftl
index 3ba375d..1b3316a 100644
--- a/exec/java-exec/src/main/resources/rest/storage/update.ftl
+++ b/exec/java-exec/src/main/resources/rest/storage/update.ftl
@@ -11,6 +11,7 @@
<#include "*/generic.ftl">
<#macro page_head>
+ <script src="http://malsup.github.com/jquery.form.js"></script>
</#macro>
<#macro page_body>
@@ -18,24 +19,53 @@
<div class="page-header">
</div>
<h3>Configuration</h3>
- <form role="form" action="/storage/config/update" method="POST">
- <input type="hidden" name="name" value="${model.name}" />
+ <form id="updateForm" role="form" action="/storage/${model.getName()}" method="POST">
+ <input type="hidden" name="name" value="${model.getName()}" />
<div class="form-group">
- <textarea class="form-control" id="config" rows="20" cols="50" name="config" style="font-family: Courier;">${model.config}</textarea>
+ <textarea class="form-control" id="config" rows="20" cols="50" name="config" style="font-family: Courier;">
+ </textarea>
</div>
<a class="btn btn-default" href="/storage">Back</a>
- <button class="btn btn-default" type="submit">
- <#if model.exists >Update<#else>Create</#if>
+ <button class="btn btn-default" type="submit" onclick="doUpdate();">
+ <#if model.exists()>Update<#else>Create</#if>
</button>
- <#if model.enabled>
- <a class="btn btn-default" href="/storage/${model.name}/config/enable/false">Disable</a>
- <#else>
- <a class="btn btn-default" href="/storage/${model.name}/config/enable/true">Enable</a>
- </#if>
- <#if model.exists>
- <a class="btn btn-danger" href="/storage/${model.name}/config/delete">Delete</a>
+ <#if model.exists()>
+ <#if model.enabled()>
+ <a id="enabled" class="btn btn-default">Disable</a>
+ <#else>
+ <a id="enabled" class="btn btn-primary">Enable</a>
+ </#if>
+ <a id="del" class="btn btn-danger" onclick="deleteFunction()">Delete</a>
</#if>
</form>
+ <br>
+ <div id="message" class="hidden alert alert-info">
+ </div>
+ <script>
+ $.get("/storage/${model.getName()}.json", function(data) {
+ $("#config").val(JSON.stringify(data.config, null, 2));
+ });
+ $("#enabled").click(function() {
+ $.get("/storage/${model.getName()}/enable/<#if model.enabled()>false<#else>true</#if>", function(data) {
+ $("#message").removeClass("hidden").text(data.result).alert();
+ setTimeout(function() { location.reload(); }, 800);
+ });
+ });
+ function doUpdate() {
+ $("#updateForm").ajaxForm(function(data) {
+ $("#message").removeClass("hidden").text(data.result).alert();
+ setTimeout(function() { location.reload(); }, 800);
+ });
+ };
+ function deleteFunction() {
+ var temp = confirm("Are you sure?");
+ if (temp == true) {
+ $.get("/storage/${model.getName()}/delete", function(data) {
+ window.location.href = "/storage";
+ });
+ }
+ };
+ </script>
</#macro>
<@page_html/>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/www/graph.js
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/www/graph.js b/exec/java-exec/src/main/resources/rest/www/graph.js
new file mode 100644
index 0000000..0173da5
--- /dev/null
+++ b/exec/java-exec/src/main/resources/rest/www/graph.js
@@ -0,0 +1,82 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ You under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. */
+
+
+$(window).load(function () {
+ document.getElementById("renderbutton").addEventListener("click", function () {
+ this.remove();
+ var queryid = window.location.href.split("/").splice(-1);
+ $.ajax({
+ type: "GET",
+ dataType: "json",
+ url: "/profiles/" + queryid + ".json",
+ success: function (profile) {
+ var colors = ["red", "green", "blue", "orange", "yellow", "pink", "purple", "gray"];
+
+ var plan = $.map(profile.plan.trim().split("\n"), function (s) {
+ return [/^([0-9-]+)( *)([a-zA-Z]*)/.exec(s).slice(1)];
+ });
+
+ // nodes
+ var g = new dagreD3.Digraph();
+ for (var i = 0; i < plan.length; i++) {
+ g.addNode(plan[i][0], {
+ label: plan[i][2],
+ fragment: parseInt(plan[i][0].split("-")[0])
+ });
+ }
+
+ // edges
+ var st = [plan[0]];
+ for (var i = 1; i < plan.length; i++) {
+ var top = st.pop();
+ while (top[1].length >= plan[i][1].length)
+ top = st.pop();
+
+ g.addEdge(null, plan[i][0], top[0]);
+
+ if (plan[i][1].length != top[1].length)
+ st.push(top);
+ if (plan[i][1].length >= top[1].length)
+ st.push(plan[i]);
+ }
+
+ // rendering
+ var renderer = new dagreD3.Renderer();
+ renderer.zoom(function () {return function (graph, root) {}});
+ var oldDrawNodes = renderer.drawNodes();
+ renderer.drawNodes(function(graph, root) {
+ var svgNodes = oldDrawNodes(graph, root);
+ svgNodes.each(function(u) {
+ d3.select(this).style("fill", colors[graph.node(u).fragment % colors.length]);
+ });
+ return svgNodes;
+ });
+
+ // page placement
+ var layout = dagreD3.layout()
+ .nodeSep(20);//.rankDir("LR");
+ var layout = renderer.layout(layout).run(g, d3.select("svg g"));
+
+ //var layout = renderer.run(g, d3.select("svg g"));
+ d3.select("svg")
+ .attr("width", layout.graph().width + 40)
+ .attr("height", layout.graph().height + 40);
+ },
+ error: function (x, y, z) {
+ console.log(x);
+ console.log(y);
+ console.log(z);
+ }
+ });
+ }, false);
+});
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/65c83582/exec/java-exec/src/main/resources/rest/www/style.css
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/www/style.css b/exec/java-exec/src/main/resources/rest/www/style.css
new file mode 100644
index 0000000..46ff811
--- /dev/null
+++ b/exec/java-exec/src/main/resources/rest/www/style.css
@@ -0,0 +1,27 @@
+/*
+ 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. */
+
+
+.node rect {
+ stroke: #000;
+ stroke-width: 1px;
+}
+
+.node text {
+ fill: #000;
+}
+
+.edgePath path {
+ stroke: #333;
+ stroke-width: 1.5px;
+ fill: none;
+}
[09/17] git commit: DRILL-1140: Add cast function from Timestamp to
Time
Posted by ja...@apache.org.
DRILL-1140: Add cast function from Timestamp to Time
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2beeda03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2beeda03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2beeda03
Branch: refs/heads/master
Commit: 2beeda036dda40b17d8f9fc440ff0d3e2309d314
Parents: c924273
Author: Mehant Baid <me...@gmail.com>
Authored: Tue Jul 15 01:33:36 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:31:18 2014 -0700
----------------------------------------------------------------------
.../drill/common/expression/ValueExpressions.java | 7 ++++++-
.../drill/exec/expr/fn/impl/DateTypeFunctions.java | 15 +++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2beeda03/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index db501aa..a1f69c2 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -60,7 +60,12 @@ public class ValueExpressions {
}
public static LogicalExpression getTime(GregorianCalendar time) {
- return new TimeExpression((int) time.getTimeInMillis());
+ int millis = time.get(GregorianCalendar.HOUR_OF_DAY) * 60 * 60 * 1000 +
+ time.get(GregorianCalendar.MINUTE) * 60 * 1000 +
+ time.get(GregorianCalendar.SECOND) * 1000 +
+ time.get(GregorianCalendar.MILLISECOND);
+
+ return new TimeExpression(millis);
}
public static LogicalExpression getTimeStamp(GregorianCalendar date) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2beeda03/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
index 2349ddf..725566f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
@@ -456,4 +456,19 @@ public class DateTypeFunctions {
out.milliSeconds = (int) (diff % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
}
}
+
+ @FunctionTemplate(name = "castTIME", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+ public static class CastTimeStampToTime implements DrillSimpleFunc {
+ @Param TimeStampHolder in;
+ @Output TimeHolder out;
+
+ @Override
+ public void setup(RecordBatch incoming) {
+ }
+
+ @Override
+ public void eval() {
+ out.value = (int) (in.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+ }
+ }
}
[15/17] git commit: DRILL-1136: Check for existance of view before
creating one when no OR REPLACE clause is provided
Posted by ja...@apache.org.
DRILL-1136: Check for existance of view before creating one when no OR REPLACE clause is provided
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/fffd0d38
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/fffd0d38
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/fffd0d38
Branch: refs/heads/master
Commit: fffd0d38af93aee16e0103a3133306c0eb07092e
Parents: 7e561de
Author: vkorukanti <ve...@gmail.com>
Authored: Tue Jul 15 09:02:46 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700
----------------------------------------------------------------------
.../exec/planner/sql/handlers/ViewHandler.java | 4 ++
.../exec/store/dfs/WorkspaceSchemaFactory.java | 5 +++
.../apache/drill/exec/sql/TestViewSupport.java | 2 +-
.../org/apache/drill/jdbc/test/TestViews.java | 47 ++++++++++++++++++++
4 files changed, 57 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fffd0d38/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
index ba70ae5..b6bb7a1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
@@ -110,6 +110,10 @@ public abstract class ViewHandler extends AbstractSqlHandler{
boolean replaced;
if (drillSchema instanceof WorkspaceSchema) {
+ WorkspaceSchema workspaceSchema = (WorkspaceSchema) drillSchema;
+ if (!createView.getReplace() && workspaceSchema.viewExists(view.getName())) {
+ return DirectPlan.createDirectPlan(context, false, "View with given name already exists in current schema");
+ }
replaced = ((WorkspaceSchema) drillSchema).createView(view);
}else{
return DirectPlan.createDirectPlan(context, false, "Schema provided was not a workspace schema.");
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fffd0d38/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 1d2bf91..54781b4 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
@@ -174,6 +174,11 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
return replaced;
}
+ public boolean viewExists(String viewName) throws Exception {
+ Path viewPath = getViewPath(viewName);
+ return fs.getUnderlying().exists(viewPath);
+ }
+
public void dropView(String viewName) throws IOException {
fs.getUnderlying().delete(getViewPath(viewName), false);
if(knownViews != null) knownViews.delete(viewName);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fffd0d38/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
index 585e931..b745baa 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
@@ -27,7 +27,7 @@ public class TestViewSupport extends BaseTestQuery{
public void referToSchemaInsideAndOutsideView() throws Exception {
String use = "use dfs_test.tmp;";
String selectInto = "create table monkey as select c_custkey, c_regionkey from cp.`tpch/customer.parquet`";
- String createView = "create view myMonkeyView as select c_custkey, c_regionkey from monkey";
+ String createView = "create or replace view myMonkeyView as select c_custkey, c_regionkey from monkey";
String selectInside = "select * from myMonkeyView;";
String use2 = "use cp;";
String selectOutside = "select * from dfs_test.tmp.myMonkeyView;";
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fffd0d38/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index 89d9573..2cbba34 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -463,4 +463,51 @@ public class TestViews extends JdbcTestQueryBase {
}
});
}
+
+ @Test
+ public void testCreateViewWhenViewAlreadyExists() throws Exception{
+ JdbcAssert.withFull("dfs_test.tmp").withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ Statement statement = connection.createStatement();
+
+ // create a view
+ ResultSet resultSet = statement.executeQuery(
+ "CREATE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id, sales_city FROM cp.`region.json`");
+ String result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ String expected = "ok=true; summary=View 'testCreateViewWhenViewAlreadyExists' " +
+ "created successfully in 'dfs_test.tmp' schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ // try to create the view with same name
+ resultSet = statement.executeQuery(
+ "CREATE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id FROM cp.`region.json`");
+ result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ expected = "ok=false; summary=View with given name already exists in current schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ // try creating the view with same name but with a OR REPLACE clause
+ resultSet = statement.executeQuery(
+ "CREATE OR REPLACE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id FROM cp.`region.json`");
+ result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ expected = "ok=true; summary=View 'testCreateViewWhenViewAlreadyExists' " +
+ "replaced successfully in 'dfs_test.tmp' schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ statement.executeQuery("drop view dfs_test.tmp.testCreateViewWhenViewAlreadyExists").close();
+
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
}
[14/17] git commit: DRILL-1145: Add testcase. Fix is in Optiq.
Posted by ja...@apache.org.
DRILL-1145: Add testcase. Fix is in Optiq.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/e5c2da0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/e5c2da0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/e5c2da0e
Branch: refs/heads/master
Commit: e5c2da0eb95df1a93d4ad909d5553757201dc903
Parents: fffd0d3
Author: vkorukanti <ve...@gmail.com>
Authored: Wed Jul 16 00:04:15 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700
----------------------------------------------------------------------
.../org/apache/drill/jdbc/test/TestViews.java | 58 ++++++++++++++++++++
1 file changed, 58 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e5c2da0e/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index 2cbba34..17772b6 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -510,4 +510,62 @@ public class TestViews extends JdbcTestQueryBase {
}
});
}
+
+ private void createViewHelper(Statement statement, String schema, String viewName, String query) throws Exception {
+ ResultSet resultSet = statement.executeQuery(query);
+ String result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ String expected = String.format("ok=true; summary=View '%s' created successfully in '%s' schema", viewName, schema);
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected), expected.equals(result));
+ }
+
+ private void queryView(Statement statement, String query, String expectedResult) throws Exception {
+ ResultSet resultSet = statement.executeQuery(query);
+ String actualResult = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", actualResult, expectedResult),
+ expectedResult.equals(actualResult));
+ }
+
+ private void dropView(Statement statement, String schema, String viewName) throws Exception {
+ if (schema != null && !schema.isEmpty()) {
+ viewName = schema + "." + viewName;
+ }
+ statement.executeQuery("drop view innerView").close();
+ }
+
+ @Test
+ public void testViewCreatedFromView() throws Exception {
+ final String schema = "dfs_test.tmp";
+ JdbcAssert.withFull(schema).withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ Statement statement = connection.createStatement();
+
+ // create a view
+ String createInnerView = "CREATE VIEW innerView AS SELECT region_id, sales_city FROM cp.`region.json`";
+ String innerViewName = "innerView";
+ createViewHelper(statement, schema, "innerView", createInnerView);
+
+ // create another view from above created view
+ String createOuterView = "CREATE VIEW outerView AS SELECT region_id FROM innerView";
+ String outerViewName = "outerView";
+ createViewHelper(statement, schema, outerViewName, createOuterView);
+
+ // query on outer view
+ String queryView = "SELECT region_id FROM outerView LIMIT 1";
+ String expectedResult = "region_id=0";
+ queryView(statement, queryView, expectedResult);
+
+ dropView(statement, schema, outerViewName);
+ dropView(statement, schema, innerViewName);
+
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
}
[05/17] git commit: DRILL-1120: Use DecimalScalePrecisionModFunction
to compute scale & precision for mod function
Posted by ja...@apache.org.
DRILL-1120: Use DecimalScalePrecisionModFunction to compute scale & precision for mod function
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/1a963744
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/1a963744
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/1a963744
Branch: refs/heads/master
Commit: 1a9637441b0436bae7159324ad3177ddd17133b0
Parents: 5080585
Author: Mehant Baid <me...@gmail.com>
Authored: Thu Jul 10 23:58:39 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:28:41 2014 -0700
----------------------------------------------------------------------
.../src/main/codegen/templates/Decimal/DecimalFunctions.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1a963744/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
index 2118cab..41a1bb7 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
@@ -562,8 +562,8 @@ public class ${type.name}Functions {
public void eval() {
if (outputPrecision == Integer.MIN_VALUE) {
- org.apache.drill.common.util.DecimalScalePrecisionDivideFunction resultScalePrec =
- new org.apache.drill.common.util.DecimalScalePrecisionDivideFunction((int) left.precision, (int) left.scale, (int) right.precision, (int) right.scale);
+ org.apache.drill.common.util.DecimalScalePrecisionModFunction resultScalePrec =
+ new org.apache.drill.common.util.DecimalScalePrecisionModFunction((int) left.precision, (int) left.scale, (int) right.precision, (int) right.scale);
outputScale = resultScalePrec.getOutputScale();
outputPrecision = resultScalePrec.getOutputPrecision();
}
@@ -1352,8 +1352,8 @@ public class ${type.name}Functions {
public void eval() {
if (outputPrecision == Integer.MIN_VALUE) {
- org.apache.drill.common.util.DecimalScalePrecisionDivideFunction resultScalePrec =
- new org.apache.drill.common.util.DecimalScalePrecisionDivideFunction((int) left.precision, (int) left.scale, (int) right.precision, (int) right.scale);
+ org.apache.drill.common.util.DecimalScalePrecisionModFunction resultScalePrec =
+ new org.apache.drill.common.util.DecimalScalePrecisionModFunction((int) left.precision, (int) left.scale, (int) right.precision, (int) right.scale);
outputScale = resultScalePrec.getOutputScale();
outputPrecision = resultScalePrec.getOutputPrecision();
}
[04/17] git commit: DRILL-1092: Ensure we have enough records while
performing merge and spill in ExternalSortBatch
Posted by ja...@apache.org.
DRILL-1092: Ensure we have enough records while performing merge and spill in ExternalSortBatch
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/5080585b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/5080585b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/5080585b
Branch: refs/heads/master
Commit: 5080585b6e2f69f49931e860de1cd4e27d08af2a
Parents: 19dbb02
Author: Mehant Baid <me...@gmail.com>
Authored: Mon Jul 14 23:28:04 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:28:02 2014 -0700
----------------------------------------------------------------------
.../exec/physical/impl/xsort/ExternalSortBatch.java | 11 +++++++----
.../exec/physical/impl/xsort/PriorityQueueCopier.java | 2 +-
.../physical/impl/xsort/PriorityQueueCopierTemplate.java | 7 ++++++-
3 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5080585b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java
index 237a631..e5da896 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java
@@ -339,6 +339,7 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> {
VectorContainer hyperBatch = new VectorContainer();
VectorContainer outputContainer = new VectorContainer();
List<BatchGroup> batchGroupList = Lists.newArrayList();
+ int recordCount = 0;
for (int i = 0; i < SPILL_BATCH_GROUP_SIZE; i++) {
if (batchGroups.size() == 0) {
break;
@@ -346,13 +347,15 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> {
if (batchGroups.peekLast().getSecondContainer() != null) {
break;
}
- batchGroupList.add(batchGroups.pollLast());
+ BatchGroup batch = batchGroups.pollLast();
+ recordCount += batch.getSv2().getCount();
+ batchGroupList.add(batch);
}
if (batchGroupList.size() == 0) {
return;
}
constructHyperBatch(batchGroupList, hyperBatch);
- createCopier(hyperBatch, batchGroupList, outputContainer);
+ createCopier(hyperBatch, batchGroupList, outputContainer, recordCount);
int count = copier.next();
assert count > 0;
@@ -535,7 +538,7 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> {
}
}
- private void createCopier(VectorAccessible batch, List<BatchGroup> batchGroupList, VectorContainer outputContainer) throws SchemaChangeException {
+ private void createCopier(VectorAccessible batch, List<BatchGroup> batchGroupList, VectorContainer outputContainer, int recordCount) throws SchemaChangeException {
try {
if (copier == null) {
CodeGenerator<PriorityQueueCopier> cg = CodeGenerator.get(PriorityQueueCopier.TEMPLATE_DEFINITION, context.getFunctionRegistry());
@@ -555,7 +558,7 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> {
outputContainer.add(v);
allocators.add(VectorAllocator.getAllocator(v, 110));
}
- copier.setup(context, copierAllocator, batch, batchGroupList, outputContainer, allocators);
+ copier.setup(context, copierAllocator, batch, batchGroupList, outputContainer, allocators, recordCount);
} catch (ClassTransformationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5080585b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopier.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopier.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopier.java
index 7122963..f2da717 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopier.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopier.java
@@ -32,7 +32,7 @@ import org.apache.drill.exec.vector.allocator.VectorAllocator;
import java.util.List;
public interface PriorityQueueCopier {
- public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing, List<VectorAllocator> allocators) throws SchemaChangeException;
+ public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing, List<VectorAllocator> allocators, int recordCnt) throws SchemaChangeException;
public int next();
public List<VectorAllocator> getAllocators();
public void cleanup();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/5080585b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java
index a74f14c..6e9c355 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java
@@ -44,7 +44,7 @@ public abstract class PriorityQueueCopierTemplate implements PriorityQueueCopier
private int targetRecordCount = ExternalSortBatch.SPILL_TARGET_RECORD_COUNT;
@Override
- public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing, List<VectorAllocator> allocators) throws SchemaChangeException {
+ public void setup(FragmentContext context, BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, VectorAccessible outgoing, List<VectorAllocator> allocators, int recordCnt) throws SchemaChangeException {
this.context = context;
this.allocator = allocator;
this.hyperBatch = hyperBatch;
@@ -64,6 +64,11 @@ public abstract class PriorityQueueCopierTemplate implements PriorityQueueCopier
siftUp();
queueSize++;
}
+
+ // Check if the we have enough records to create BatchData with two containers.
+ if (recordCnt < (2 * targetRecordCount)) {
+ targetRecordCount = (recordCnt / 2);
+ }
}
@Override
[08/17] git commit: DRILL-1138: Explicit casting to boolean fails
Posted by ja...@apache.org.
DRILL-1138: Explicit casting to boolean fails
+ Renamed ConvertUtil to ByteBufUtil
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/c9242731
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/c9242731
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/c9242731
Branch: refs/heads/master
Commit: c9242731096fd83315614fcaf11d6ea5c7a28eae
Parents: c4a82f5
Author: Aditya Kishore <ad...@maprtech.com>
Authored: Mon Jul 14 02:23:19 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:30:16 2014 -0700
----------------------------------------------------------------------
.../common/expression/fn/CastFunctions.java | 1 +
.../exec/expr/fn/impl/SimpleCastFunctions.java | 75 +++++++
.../expr/fn/impl/conv/BigIntBEConvertFrom.java | 2 +-
.../expr/fn/impl/conv/BigIntBEConvertTo.java | 2 +-
.../expr/fn/impl/conv/BigIntConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/BigIntConvertTo.java | 2 +-
.../fn/impl/conv/BigIntVLongConvertFrom.java | 2 +-
.../expr/fn/impl/conv/BigIntVLongConvertTo.java | 4 +-
.../fn/impl/conv/BooleanByteConvertFrom.java | 2 +-
.../expr/fn/impl/conv/BooleanByteConvertTo.java | 2 +-
.../fn/impl/conv/DateEpochBEConvertFrom.java | 2 +-
.../expr/fn/impl/conv/DateEpochBEConvertTo.java | 2 +-
.../expr/fn/impl/conv/DateEpochConvertFrom.java | 2 +-
.../expr/fn/impl/conv/DateEpochConvertTo.java | 2 +-
.../expr/fn/impl/conv/DoubleConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/DoubleConvertTo.java | 2 +-
.../expr/fn/impl/conv/FloatConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/FloatConvertTo.java | 2 +-
.../expr/fn/impl/conv/IntBEConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/IntBEConvertTo.java | 2 +-
.../exec/expr/fn/impl/conv/IntConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/IntConvertTo.java | 2 +-
.../expr/fn/impl/conv/IntVIntConvertFrom.java | 2 +-
.../expr/fn/impl/conv/IntVIntConvertTo.java | 4 +-
.../exec/expr/fn/impl/conv/JsonConvertTo.java | 4 +-
.../fn/impl/conv/SmallIntBEConvertFrom.java | 2 +-
.../expr/fn/impl/conv/SmallIntBEConvertTo.java | 2 +-
.../expr/fn/impl/conv/SmallIntConvertFrom.java | 2 +-
.../expr/fn/impl/conv/SmallIntConvertTo.java | 2 +-
.../fn/impl/conv/TimeEpochBEConvertFrom.java | 2 +-
.../expr/fn/impl/conv/TimeEpochBEConvertTo.java | 2 +-
.../expr/fn/impl/conv/TimeEpochConvertFrom.java | 2 +-
.../expr/fn/impl/conv/TimeEpochConvertTo.java | 2 +-
.../expr/fn/impl/conv/TinyIntConvertFrom.java | 2 +-
.../expr/fn/impl/conv/TinyIntConvertTo.java | 2 +-
.../expr/fn/impl/conv/UInt8ConvertFrom.java | 2 +-
.../exec/expr/fn/impl/conv/UInt8ConvertTo.java | 2 +-
.../drill/exec/planner/logical/DrillOptiq.java | 1 +
.../org/apache/drill/exec/util/ByteBufUtil.java | 220 +++++++++++++++++++
.../org/apache/drill/exec/util/ConvertUtil.java | 210 ------------------
.../physical/impl/TestConvertFunctions.java | 6 +-
.../drill/exec/sql/TestSimpleCastFunctions.java | 35 +++
42 files changed, 373 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java b/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
index e6a814f..4ff796d 100644
--- a/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
@@ -29,6 +29,7 @@ public class CastFunctions {
static {
TYPE2FUNC.put(MinorType.BIGINT, "castBIGINT");
TYPE2FUNC.put(MinorType.INT, "castINT");
+ TYPE2FUNC.put(MinorType.BIT, "castBIT");
TYPE2FUNC.put(MinorType.TINYINT, "castTINYINT");
TYPE2FUNC.put(MinorType.FLOAT4, "castFLOAT4");
TYPE2FUNC.put(MinorType.FLOAT8, "castFLOAT8");
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleCastFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleCastFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleCastFunctions.java
new file mode 100644
index 0000000..83c5540
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleCastFunctions.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.ByteBuf;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class SimpleCastFunctions {
+ public static final ByteBuf FALSE = org.apache.drill.exec.util.ByteBufUtil.createBuffer(new byte[] {'f', 'a', 'l', 's', 'e'});
+ public static final ByteBuf TRUE = org.apache.drill.exec.util.ByteBufUtil.createBuffer(new byte[] {'t', 'r', 'u', 'e'});
+
+ @FunctionTemplate(names = {"castBIT", "castBOOLEAN"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.NULL_IF_NULL)
+ public static class CastVarCharBoolean implements DrillSimpleFunc {
+
+ @Param VarCharHolder in;
+ @Output BitHolder out;
+
+ public void setup(RecordBatch b) {}
+
+ public void eval() {
+ byte[] buf = new byte[in.end - in.start];
+ in.buffer.getBytes(in.start, buf, 0, in.end - in.start);
+ String input = new String(buf, com.google.common.base.Charsets.UTF_8).toLowerCase();
+ if ("true".equals(input)) {
+ out.value = 1;
+ } else if ("false".equals(input)) {
+ out.value = 0;
+ } else {
+ throw new IllegalArgumentException("Invalid value for boolean: " + input);
+ }
+ }
+ }
+
+ @FunctionTemplate(name = "castVARCHAR", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.NULL_IF_NULL)
+ public static class CastBooleanVarChar implements DrillSimpleFunc {
+
+ @Param BitHolder in;
+ @Param BigIntHolder len;
+ @Output VarCharHolder out;
+
+ public void setup(RecordBatch b) {}
+
+ public void eval() {
+ io.netty.buffer.ByteBuf buffer = in.value == 1 ? org.apache.drill.exec.expr.fn.impl.SimpleCastFunctions.TRUE : org.apache.drill.exec.expr.fn.impl.SimpleCastFunctions.FALSE;
+ out.buffer = buffer;
+ out.start = 0;
+ out.end = Math.min((int)len.value, buffer.capacity()); // truncate if target type has length smaller than that of input's string
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
index 01da0b1..dc0f6b7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertFrom.java
@@ -38,7 +38,7 @@ public class BigIntBEConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
out.value = Long.reverseBytes(in.buffer.readLong());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
index 7122937..696ea25 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntBEConvertTo.java
@@ -39,7 +39,7 @@ public class BigIntBEConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
index 093de0f..2f303c4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertFrom.java
@@ -39,7 +39,7 @@ public class BigIntConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readLong();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
index 70bb6e7..8c76113 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntConvertTo.java
@@ -40,7 +40,7 @@ public class BigIntConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
index d7bbfcc..f398071 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertFrom.java
@@ -38,6 +38,6 @@ public class BigIntVLongConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- out.value = org.apache.drill.exec.util.ConvertUtil.HadoopWritables.readVLong(in.buffer, in.start, in.end);
+ out.value = org.apache.drill.exec.util.ByteBufUtil.HadoopWritables.readVLong(in.buffer, in.start, in.end);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
index dbf764d..78564f6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BigIntVLongConvertTo.java
@@ -42,13 +42,13 @@ public class BigIntVLongConvertTo implements DrillSimpleFunc {
/* Hadoop Variable length integer (represented in the same way as a long)
* occupies between 1-9 bytes.
*/
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(9);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(9);
}
@Override
public void eval() {
buffer.clear();
- org.apache.drill.exec.util.ConvertUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
+ org.apache.drill.exec.util.ByteBufUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
out.buffer = buffer;
out.start = 0;
out.end = buffer.readableBytes();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
index f72d507..d03c951 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertFrom.java
@@ -39,7 +39,7 @@ public class BooleanByteConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readByte()==0 ? 0 : 1;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
index 959deb0..0feb08b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/BooleanByteConvertTo.java
@@ -40,7 +40,7 @@ public class BooleanByteConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(1);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(1);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
index 75bf8d6..c511935 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertFrom.java
@@ -38,7 +38,7 @@ public class DateEpochBEConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
long epochMillis = Long.reverseBytes(in.buffer.readLong());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
index 98b561c..9e2026a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochBEConvertTo.java
@@ -39,7 +39,7 @@ public class DateEpochBEConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
index 713016c..fa1c063 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertFrom.java
@@ -39,7 +39,7 @@ public class DateEpochConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
long epochMillis = in.buffer.readLong();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
index f0e604e..90fb319 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DateEpochConvertTo.java
@@ -40,7 +40,7 @@ public class DateEpochConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
index df0bae7..1fa9166 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertFrom.java
@@ -39,7 +39,7 @@ public class DoubleConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readDouble();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
index 1f5c38f..5487ee0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleConvertTo.java
@@ -40,7 +40,7 @@ public class DoubleConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
index 9f42b57..4ed553b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertFrom.java
@@ -39,7 +39,7 @@ public class FloatConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readFloat();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
index a1d8c7c..ec06225 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatConvertTo.java
@@ -40,7 +40,7 @@ public class FloatConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(4);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
index d235c66..969adde 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertFrom.java
@@ -38,7 +38,7 @@ public class IntBEConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
in.buffer.readerIndex(in.start);
out.value = Integer.reverseBytes(in.buffer.readInt());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
index cd13c31..6de4f0a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntBEConvertTo.java
@@ -39,7 +39,7 @@ public class IntBEConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(4);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
index 4563b8e..9948e7a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertFrom.java
@@ -39,7 +39,7 @@ public class IntConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 4);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readInt();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
index 8531608..c1f8977 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntConvertTo.java
@@ -40,7 +40,7 @@ public class IntConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(4);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(4);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
index acb2666..0cf729f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertFrom.java
@@ -38,6 +38,6 @@ public class IntVIntConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- out.value = org.apache.drill.exec.util.ConvertUtil.HadoopWritables.readVInt(in.buffer, in.start, in.end);
+ out.value = org.apache.drill.exec.util.ByteBufUtil.HadoopWritables.readVInt(in.buffer, in.start, in.end);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
index 383d001..52680c8 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/IntVIntConvertTo.java
@@ -42,13 +42,13 @@ public class IntVIntConvertTo implements DrillSimpleFunc {
/* Hadoop Variable length integer (represented in the same way as a long)
* occupies between 1-9 bytes.
*/
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(9);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(9);
}
@Override
public void eval() {
buffer.clear();
- org.apache.drill.exec.util.ConvertUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
+ org.apache.drill.exec.util.ByteBufUtil.HadoopWritables.writeVLong(buffer, 0, 9, in.value);
out.buffer = buffer;
out.start = 0;
out.end = buffer.readableBytes();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/JsonConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/JsonConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/JsonConvertTo.java
index ca1e01f..8b0e811 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/JsonConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/JsonConvertTo.java
@@ -51,7 +51,7 @@ public class JsonConvertTo {
@Workspace ByteBuf buffer;
public void setup(RecordBatch incoming){
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(256);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(256);
}
public void eval(){
@@ -70,7 +70,7 @@ public class JsonConvertTo {
byte [] bytea = stream.toByteArray();
if (bytea.length > buffer.capacity()) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(bytea.length);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(bytea.length);
out.buffer = buffer;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
index 3ad2d81..1f22575 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertFrom.java
@@ -39,7 +39,7 @@ public class SmallIntBEConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
in.buffer.readerIndex(in.start);
out.value = Short.reverseBytes(in.buffer.readShort());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
index c22cad1..227932a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntBEConvertTo.java
@@ -40,7 +40,7 @@ public class SmallIntBEConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(2);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(2);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
index 6d4832b..463ec35 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertFrom.java
@@ -39,7 +39,7 @@ public class SmallIntConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 2);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readShort();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
index 3443ec3..db74fad 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/SmallIntConvertTo.java
@@ -40,7 +40,7 @@ public class SmallIntConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(2);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(2);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
index c426d28..7aee12d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertFrom.java
@@ -38,7 +38,7 @@ public class TimeEpochBEConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
long epochMillis = Long.reverseBytes(in.buffer.readLong());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
index 66a5e84..e19850e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochBEConvertTo.java
@@ -39,7 +39,7 @@ public class TimeEpochBEConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
index aa23050..9fb272b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertFrom.java
@@ -39,7 +39,7 @@ public class TimeEpochConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
long epochMillis = in.buffer.readLong();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
index b97c604..56b76e0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TimeEpochConvertTo.java
@@ -40,7 +40,7 @@ public class TimeEpochConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
index 367fd6b..4380c13 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertFrom.java
@@ -40,7 +40,7 @@ public class TinyIntConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 1);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readByte();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
index 3a58105..afd1eb6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/TinyIntConvertTo.java
@@ -41,7 +41,7 @@ public class TinyIntConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(1);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(1);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
index 83fddc9..dab73a7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertFrom.java
@@ -39,7 +39,7 @@ public class UInt8ConvertFrom implements DrillSimpleFunc {
@Override
public void eval() {
- org.apache.drill.exec.util.ConvertUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
+ org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8);
in.buffer.readerIndex(in.start);
out.value = in.buffer.readLong();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
index 4e4d84d..0322d1a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/UInt8ConvertTo.java
@@ -40,7 +40,7 @@ public class UInt8ConvertTo implements DrillSimpleFunc {
@Override
public void setup(RecordBatch incoming) {
- buffer = org.apache.drill.exec.util.ConvertUtil.createBuffer(8);
+ buffer = org.apache.drill.exec.util.ByteBufUtil.createBuffer(8);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
index deb3049..75a5ebc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
@@ -251,6 +251,7 @@ public class DrillOptiq {
case "INTERVAL_YEAR_MONTH": castType = Types.required(MinorType.INTERVALYEAR); break;
case "INTERVAL_DAY_TIME": castType = Types.required(MinorType.INTERVALDAY); break;
+ case "BOOLEAN": castType = Types.required(MinorType.BIT); break;
case "ANY": return arg; // Type will be same as argument.
default: castType = Types.required(MinorType.valueOf(call.getType().getSqlTypeName().getName()));
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/util/ByteBufUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ByteBufUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ByteBufUtil.java
new file mode 100644
index 0000000..e7bdbcf
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ByteBufUtil.java
@@ -0,0 +1,220 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.util;
+
+import static java.nio.ByteOrder.LITTLE_ENDIAN;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import java.io.DataInput;
+
+import org.apache.drill.common.util.DrillStringUtils;
+
+public class ByteBufUtil {
+ /**
+ * Creates a wrapped {@link ByteBuf} of {@code size} number of bytes with
+ * the Drill's default endianness(LITTLE_ENDIAN).
+ *
+ * @param size
+ * @return
+ */
+ public static ByteBuf createBuffer(int size) {
+ return Unpooled.wrappedBuffer(new byte[size]).order(LITTLE_ENDIAN);
+ }
+
+ /**
+ * Creates a {@link ByteBuf} which wraps the provided byte array with
+ * the Drill's default endianness(LITTLE_ENDIAN).
+ *
+ * @param size
+ * @return
+ */
+ public static ByteBuf createBuffer(byte[] source) {
+ return Unpooled.wrappedBuffer(source).order(LITTLE_ENDIAN);
+ }
+
+ /**
+ * Verifies that the the space provided in the buffer is of specified size.
+ * @throws IllegalArgumentException if the specified boundaries do not describe the expected size.
+ */
+ public static void checkBufferLength(ByteBuf buffer, int start, int end, int requiredLen) {
+ int actualLen = (end - start);
+ if (actualLen != requiredLen) {
+ throw new IllegalArgumentException(String.format("Wrong length %d(%d-%d) in the buffer '%s', expected %d.",
+ actualLen, end, start, DrillStringUtils.toBinaryString(buffer, start, end), requiredLen));
+ }
+ }
+
+ /**
+ * Modeled after {@code org.apache.hadoop.io.WritableUtils}.
+ * We copy the code to avoid wrapping {@link ByteBuf} to/from {@link DataInput}.
+ */
+ public static class HadoopWritables {
+ /**
+ * Serializes an integer to a binary stream with zero-compressed encoding.
+ * For -120 <= i <= 127, only one byte is used with the actual value.
+ * For other values of i, the first byte value indicates whether the
+ * integer is positive or negative, and the number of bytes that follow.
+ * If the first byte value v is between -121 and -124, the following integer
+ * is positive, with number of bytes that follow are -(v+120).
+ * If the first byte value v is between -125 and -128, the following integer
+ * is negative, with number of bytes that follow are -(v+124). Bytes are
+ * stored in the high-non-zero-byte-first order.
+ *
+ * @param buffer ByteBuf to read from
+ * @param i Integer to be serialized
+ */
+ public static void writeVInt(ByteBuf buffer, int start, int end, int i) {
+ writeVLong(buffer, start, end, i);
+ }
+
+ /**
+ * Serializes a long to a binary stream with zero-compressed encoding.
+ * For -112 <= i <= 127, only one byte is used with the actual value.
+ * For other values of i, the first byte value indicates whether the
+ * long is positive or negative, and the number of bytes that follow.
+ * If the first byte value v is between -113 and -120, the following long
+ * is positive, with number of bytes that follow are -(v+112).
+ * If the first byte value v is between -121 and -128, the following long
+ * is negative, with number of bytes that follow are -(v+120). Bytes are
+ * stored in the high-non-zero-byte-first order.
+ *
+ * @param buffer ByteBuf to write to
+ * @param i Long to be serialized
+ */
+ public static void writeVLong(ByteBuf buffer, int start, int end, long i) {
+ int availableBytes = (end-start);
+ if (availableBytes < getVIntSize(i)) {
+ throw new NumberFormatException("Expected " + getVIntSize(i) + " bytes but the buffer '"
+ + DrillStringUtils.toBinaryString(buffer, start, end) + "' has only "
+ + availableBytes + " bytes.");
+ }
+ buffer.writerIndex(start);
+
+ if (i >= -112 && i <= 127) {
+ buffer.writeByte((byte)i);
+ return;
+ }
+
+ int len = -112;
+ if (i < 0) {
+ i ^= -1L; // take one's complement'
+ len = -120;
+ }
+
+ long tmp = i;
+ while (tmp != 0) {
+ tmp = tmp >> 8;
+ len--;
+ }
+
+ buffer.writeByte((byte)len);
+
+ len = (len < -120) ? -(len + 120) : -(len + 112);
+
+ for (int idx = len; idx != 0; idx--) {
+ int shiftbits = (idx - 1) * 8;
+ long mask = 0xFFL << shiftbits;
+ buffer.writeByte((byte)((i & mask) >> shiftbits));
+ }
+ }
+
+ /**
+ * Reads a zero-compressed encoded integer from input stream and returns it.
+ * @param buffer ByteBuf to read from
+ * @return deserialized integer from stream.
+ */
+ public static int readVInt(ByteBuf buffer, int start, int end) {
+ long n = readVLong(buffer, start, end);
+ if ((n > Integer.MAX_VALUE) || (n < Integer.MIN_VALUE)) {
+ throw new NumberFormatException("Value " + n + " too long to fit in integer");
+ }
+ return (int)n;
+ }
+
+ /**
+ * Reads a zero-compressed encoded long from input stream and returns it.
+ * @param buffer ByteBuf to read from
+ * @return deserialized long from stream.
+ */
+ public static long readVLong(ByteBuf buffer, int start, int end) {
+ buffer.readerIndex(start);
+ byte firstByte = buffer.readByte();
+ int len = decodeVIntSize(firstByte);
+ int availableBytes = (end-start);
+ if (len == 1) {
+ return firstByte;
+ } else if (availableBytes < len) {
+ throw new NumberFormatException("Expected " + len + " bytes but the buffer '"
+ + DrillStringUtils.toBinaryString(buffer, start, end) + "' has "
+ + availableBytes + " bytes.");
+ }
+
+ long longValue = 0;
+ for (int idx = 0; idx < len-1; idx++) {
+ byte byteValue = buffer.readByte();
+ longValue = longValue << 8;
+ longValue = longValue | (byteValue & 0xFF);
+ }
+ return (isNegativeVInt(firstByte) ? (longValue ^ -1L) : longValue);
+ }
+
+ /**
+ * Parse the first byte of a vint/vlong to determine the number of bytes
+ * @param value the first byte of the vint/vlong
+ * @return the total number of bytes (1 to 9)
+ */
+ public static int decodeVIntSize(byte value) {
+ if (value >= -112) {
+ return 1;
+ } else if (value < -120) {
+ return -119 - value;
+ }
+ return -111 - value;
+ }
+
+ /**
+ * Get the encoded length if an integer is stored in a variable-length format
+ * @return the encoded length
+ */
+ public static int getVIntSize(long i) {
+ if (i >= -112 && i <= 127) {
+ return 1;
+ }
+
+ if (i < 0) {
+ i ^= -1L; // take one's complement'
+ }
+ // find the number of bytes with non-leading zeros
+ int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i);
+ // find the number of data bytes + length byte
+ return (dataBits + 7) / 8 + 1;
+ }
+
+ /**
+ * Given the first byte of a vint/vlong, determine the sign
+ * @param value the first byte
+ * @return is the value negative
+ */
+ public static boolean isNegativeVInt(byte value) {
+ return value < -120 || (value >= -112 && value < 0);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
deleted file mode 100644
index ffcb7d1..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ConvertUtil.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.util;
-
-import static java.nio.ByteOrder.LITTLE_ENDIAN;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-
-import java.io.DataInput;
-
-import org.apache.drill.common.util.DrillStringUtils;
-import org.apache.drill.exec.expr.fn.impl.StringFunctionUtil;
-
-public class ConvertUtil {
- /**
- * Creates a wrapped {@link ByteBuf} of {@code size} number of bytes with
- * the Drill's default endianness(LITTLE_ENDIAN).
- *
- * @param size
- * @return
- */
- public static ByteBuf createBuffer(int size) {
- return Unpooled.wrappedBuffer(new byte[size]).order(LITTLE_ENDIAN);
- }
-
- /**
- * Verifies that the the space provided in the buffer is of specified size.
- * @throws IllegalArgumentException if the specified boundaries do not describe the expected size.
- */
- public static void checkBufferLength(ByteBuf buffer, int start, int end, int requiredLen) {
- int actualLen = (end - start);
- if (actualLen != requiredLen) {
- throw new IllegalArgumentException(String.format("Wrong length %d(%d-%d) in the buffer '%s', expected %d.",
- actualLen, end, start, DrillStringUtils.toBinaryString(buffer, start, end), requiredLen));
- }
- }
-
- /**
- * Modeled after {@code org.apache.hadoop.io.WritableUtils}.
- * We copy the code to avoid wrapping {@link ByteBuf} to/from {@link DataInput}.
- */
- public static class HadoopWritables {
- /**
- * Serializes an integer to a binary stream with zero-compressed encoding.
- * For -120 <= i <= 127, only one byte is used with the actual value.
- * For other values of i, the first byte value indicates whether the
- * integer is positive or negative, and the number of bytes that follow.
- * If the first byte value v is between -121 and -124, the following integer
- * is positive, with number of bytes that follow are -(v+120).
- * If the first byte value v is between -125 and -128, the following integer
- * is negative, with number of bytes that follow are -(v+124). Bytes are
- * stored in the high-non-zero-byte-first order.
- *
- * @param buffer ByteBuf to read from
- * @param i Integer to be serialized
- */
- public static void writeVInt(ByteBuf buffer, int start, int end, int i) {
- writeVLong(buffer, start, end, i);
- }
-
- /**
- * Serializes a long to a binary stream with zero-compressed encoding.
- * For -112 <= i <= 127, only one byte is used with the actual value.
- * For other values of i, the first byte value indicates whether the
- * long is positive or negative, and the number of bytes that follow.
- * If the first byte value v is between -113 and -120, the following long
- * is positive, with number of bytes that follow are -(v+112).
- * If the first byte value v is between -121 and -128, the following long
- * is negative, with number of bytes that follow are -(v+120). Bytes are
- * stored in the high-non-zero-byte-first order.
- *
- * @param buffer ByteBuf to write to
- * @param i Long to be serialized
- */
- public static void writeVLong(ByteBuf buffer, int start, int end, long i) {
- int availableBytes = (end-start);
- if (availableBytes < getVIntSize(i)) {
- throw new NumberFormatException("Expected " + getVIntSize(i) + " bytes but the buffer '"
- + DrillStringUtils.toBinaryString(buffer, start, end) + "' has only "
- + availableBytes + " bytes.");
- }
- buffer.writerIndex(start);
-
- if (i >= -112 && i <= 127) {
- buffer.writeByte((byte)i);
- return;
- }
-
- int len = -112;
- if (i < 0) {
- i ^= -1L; // take one's complement'
- len = -120;
- }
-
- long tmp = i;
- while (tmp != 0) {
- tmp = tmp >> 8;
- len--;
- }
-
- buffer.writeByte((byte)len);
-
- len = (len < -120) ? -(len + 120) : -(len + 112);
-
- for (int idx = len; idx != 0; idx--) {
- int shiftbits = (idx - 1) * 8;
- long mask = 0xFFL << shiftbits;
- buffer.writeByte((byte)((i & mask) >> shiftbits));
- }
- }
-
- /**
- * Reads a zero-compressed encoded integer from input stream and returns it.
- * @param buffer ByteBuf to read from
- * @return deserialized integer from stream.
- */
- public static int readVInt(ByteBuf buffer, int start, int end) {
- long n = readVLong(buffer, start, end);
- if ((n > Integer.MAX_VALUE) || (n < Integer.MIN_VALUE)) {
- throw new NumberFormatException("Value " + n + " too long to fit in integer");
- }
- return (int)n;
- }
-
- /**
- * Reads a zero-compressed encoded long from input stream and returns it.
- * @param buffer ByteBuf to read from
- * @return deserialized long from stream.
- */
- public static long readVLong(ByteBuf buffer, int start, int end) {
- buffer.readerIndex(start);
- byte firstByte = buffer.readByte();
- int len = decodeVIntSize(firstByte);
- int availableBytes = (end-start);
- if (len == 1) {
- return firstByte;
- } else if (availableBytes < len) {
- throw new NumberFormatException("Expected " + len + " bytes but the buffer '"
- + DrillStringUtils.toBinaryString(buffer, start, end) + "' has "
- + availableBytes + " bytes.");
- }
-
- long longValue = 0;
- for (int idx = 0; idx < len-1; idx++) {
- byte byteValue = buffer.readByte();
- longValue = longValue << 8;
- longValue = longValue | (byteValue & 0xFF);
- }
- return (isNegativeVInt(firstByte) ? (longValue ^ -1L) : longValue);
- }
-
- /**
- * Parse the first byte of a vint/vlong to determine the number of bytes
- * @param value the first byte of the vint/vlong
- * @return the total number of bytes (1 to 9)
- */
- public static int decodeVIntSize(byte value) {
- if (value >= -112) {
- return 1;
- } else if (value < -120) {
- return -119 - value;
- }
- return -111 - value;
- }
-
- /**
- * Get the encoded length if an integer is stored in a variable-length format
- * @return the encoded length
- */
- public static int getVIntSize(long i) {
- if (i >= -112 && i <= 127) {
- return 1;
- }
-
- if (i < 0) {
- i ^= -1L; // take one's complement'
- }
- // find the number of bytes with non-leading zeros
- int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i);
- // find the number of data bytes + length byte
- return (dataBits + 7) / 8 + 1;
- }
-
- /**
- * Given the first byte of a vint/vlong, determine the sign
- * @param value the first byte
- * @return is the value negative
- */
- public static boolean isNegativeVInt(byte value) {
- return value < -120 || (value >= -112 && value < 0);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
index 9f7c7a6..0a021ad 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java
@@ -36,8 +36,8 @@ import org.apache.drill.exec.record.RecordBatchLoader;
import org.apache.drill.exec.rpc.user.QueryResultBatch;
import org.apache.drill.exec.rpc.user.UserServer;
import org.apache.drill.exec.server.DrillbitContext;
-import org.apache.drill.exec.util.ConvertUtil;
-import org.apache.drill.exec.util.ConvertUtil.HadoopWritables;
+import org.apache.drill.exec.util.ByteBufUtil;
+import org.apache.drill.exec.util.ByteBufUtil.HadoopWritables;
import org.apache.drill.exec.util.VectorUtil;
import org.apache.drill.exec.vector.ValueVector;
import org.apache.drill.exec.vector.VarCharVector;
@@ -323,7 +323,7 @@ public class TestConvertFunctions extends BaseTestQuery {
public void testHadooopVInt() throws Exception {
final int _0 = 0;
final int _9 = 9;
- final ByteBuf buffer = ConvertUtil.createBuffer(_9);
+ final ByteBuf buffer = ByteBufUtil.createBuffer(_9);
long longVal = 0;
buffer.clear();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c9242731/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSimpleCastFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSimpleCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSimpleCastFunctions.java
new file mode 100644
index 0000000..4dae7fe
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestSimpleCastFunctions.java
@@ -0,0 +1,35 @@
+/**
+ * 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.sql;
+
+import org.apache.drill.BaseTestQuery;
+import org.junit.Test;
+
+public class TestSimpleCastFunctions extends BaseTestQuery {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleCastFunctions.class);
+
+ @Test
+ public void castFromBoolean() throws Exception {
+ test("select cast(false as varchar(5)), cast(true as varchar(4)), cast((1 < 5) as varchar(4)) from sys.options limit 1;");
+ }
+
+ @Test
+ public void castToBoolean() throws Exception {
+ test("select cast('false' as boolean), cast('true' as boolean) from sys.options limit 1;");
+ }
+}
[06/17] git commit: DRILL-1121: Round up digits while performing mod,
decimal division
Posted by ja...@apache.org.
DRILL-1121: Round up digits while performing mod, decimal division
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/a6e296cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/a6e296cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/a6e296cd
Branch: refs/heads/master
Commit: a6e296cde2523976218f5ca5064a8c8b93b3d5e2
Parents: 1a96374
Author: Mehant Baid <me...@gmail.com>
Authored: Thu Jul 10 23:23:17 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:29:07 2014 -0700
----------------------------------------------------------------------
.../src/main/codegen/templates/Decimal/DecimalFunctions.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a6e296cd/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
index 41a1bb7..03e9a24 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
@@ -537,7 +537,7 @@ public class ${type.name}Functions {
java.math.BigDecimal numerator = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromByteBuf(left.buffer, left.start, left.nDecimalDigits, left.scale, true);
java.math.BigDecimal denominator = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromByteBuf(right.buffer, right.start, right.nDecimalDigits, right.scale, true);
- java.math.BigDecimal output = numerator.divide(denominator, (int) result.scale, java.math.BigDecimal.ROUND_DOWN);
+ java.math.BigDecimal output = numerator.divide(denominator, (int) result.scale, java.math.BigDecimal.ROUND_HALF_UP);
org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(output, result.buffer, result.start, result.scale, result.precision, result.nDecimalDigits);
}
@@ -576,7 +576,7 @@ public class ${type.name}Functions {
java.math.BigDecimal denominator = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromByteBuf(right.buffer, right.start, right.nDecimalDigits, right.scale, true);
java.math.BigDecimal output = numerator.remainder(denominator);
- output.setScale(result.scale, java.math.BigDecimal.ROUND_DOWN);
+ output.setScale(result.scale, java.math.BigDecimal.ROUND_HALF_UP);
org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(output, result.buffer, result.start, result.scale, result.precision, result.nDecimalDigits);
}
@@ -1331,7 +1331,7 @@ public class ${type.name}Functions {
java.math.BigDecimal numerator = new java.math.BigDecimal(java.math.BigInteger.valueOf(left.value), left.scale);
java.math.BigDecimal denominator = new java.math.BigDecimal(java.math.BigInteger.valueOf(right.value), right.scale);
- java.math.BigDecimal output = numerator.divide(denominator, (int) result.scale, java.math.BigDecimal.ROUND_DOWN);
+ java.math.BigDecimal output = numerator.divide(denominator, (int) result.scale, java.math.BigDecimal.ROUND_HALF_UP);
result.value = output.unscaledValue().${type.storage}Value();
}
@@ -1363,7 +1363,7 @@ public class ${type.name}Functions {
java.math.BigDecimal denominator = new java.math.BigDecimal(java.math.BigInteger.valueOf(right.value), right.scale);
java.math.BigDecimal output = numerator.remainder(denominator);
- output.setScale(result.scale, java.math.BigDecimal.ROUND_DOWN);
+ output.setScale(result.scale, java.math.BigDecimal.ROUND_HALF_UP);
result.value = output.unscaledValue().${type.storage}Value();
}
[17/17] git commit: DRILL-990: Add schema mutability property to
InfoSchema.SCHEMATA table.
Posted by ja...@apache.org.
DRILL-990: Add schema mutability property to InfoSchema.SCHEMATA table.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/d3998618
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/d3998618
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/d3998618
Branch: refs/heads/master
Commit: d39986188d17af92fc8c91b61a0f086a65f95d1a
Parents: 111c1a8
Author: vkorukanti <ve...@gmail.com>
Authored: Mon Jul 14 18:32:57 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700
----------------------------------------------------------------------
.../exec/store/ischema/InfoSchemaTable.java | 3 ++-
.../exec/store/ischema/RecordGenerator.java | 2 +-
.../apache/drill/exec/store/ischema/Records.java | 4 +++-
.../apache/drill/jdbc/test/TestMetadataDDL.java | 19 +++++++++++++++++++
4 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3998618/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 e6d39ed..0cf0481 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
@@ -101,7 +101,8 @@ public abstract class InfoSchemaTable{
Field.create("CATALOG_NAME", VARCHAR),
Field.create("SCHEMA_NAME", VARCHAR),
Field.create("SCHEMA_OWNER", VARCHAR),
- Field.create("TYPE", VARCHAR));
+ Field.create("TYPE", VARCHAR),
+ Field.create("IS_MUTABLE", VARCHAR));
public Schemata() {
super("SCHEMATA", fields);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3998618/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/RecordGenerator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/RecordGenerator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/RecordGenerator.java
index df67da1..00ab0a0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/RecordGenerator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/RecordGenerator.java
@@ -116,7 +116,7 @@ public abstract class RecordGenerator {
public boolean visitSchema(String schemaName, SchemaPlus schema) {
if (shouldVisitSchema(schema) && schemaName != null && !schemaName.isEmpty()) {
AbstractSchema as = schema.unwrap(AbstractSchema.class);
- records.add(new Records.Schema("DRILL", schemaName, "<owner>", as.getTypeName()));
+ records.add(new Records.Schema("DRILL", schemaName, "<owner>", as.getTypeName(), as.isMutable()));
}
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3998618/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/Records.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/Records.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/Records.java
index 9bb182f..ec8ee2b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/Records.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/Records.java
@@ -124,12 +124,14 @@ public class Records {
public final String SCHEMA_NAME;
public final String SCHEMA_OWNER;
public final String TYPE;
+ public final String IS_MUTABLE;
- public Schema(String catalog, String name, String owner, String type) {
+ public Schema(String catalog, String name, String owner, String type, boolean isMutable) {
this.CATALOG_NAME = catalog;
this.SCHEMA_NAME = name;
this.SCHEMA_OWNER = owner;
this.TYPE = type;
+ this.IS_MUTABLE = isMutable ? "YES" : "NO";
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3998618/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
index 6d09976..b1fc193 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
@@ -54,6 +54,25 @@ public class TestMetadataDDL extends JdbcTestQueryBase {
}
@Test
+ public void testSchemata() throws Exception{
+ JdbcAssert.withNoDefaultSchema()
+ .sql("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA")
+ .returns(
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.root; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs.tmp; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=YES\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=sys; SCHEMA_OWNER=<owner>; TYPE=system-tables; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.home; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=dfs_test.tmp; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=YES\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=cp.default; SCHEMA_OWNER=<owner>; TYPE=file; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=hive_test.default; SCHEMA_OWNER=<owner>; TYPE=hive; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=hive_test.db1; SCHEMA_OWNER=<owner>; TYPE=hive; IS_MUTABLE=NO\n" +
+ "CATALOG_NAME=DRILL; SCHEMA_NAME=INFORMATION_SCHEMA; SCHEMA_OWNER=<owner>; TYPE=ischema; IS_MUTABLE=NO\n"
+ );
+ }
+
+ @Test
public void testShowTables() throws Exception{
JdbcAssert.withFull("hive_test.default")
.sql("SHOW TABLES")
[13/17] git commit: DRILL-1114: Fix a bug in resolving tables in
schema where view is created
Posted by ja...@apache.org.
DRILL-1114: Fix a bug in resolving tables in schema where view is created
Store the current schema path where view is created within view and use that schema path when expanding the view as part of query planning.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/7e561def
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/7e561def
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/7e561def
Branch: refs/heads/master
Commit: 7e561def4bceca83a302d85154274eec199cdd9c
Parents: d399861
Author: vkorukanti <ve...@gmail.com>
Authored: Tue Jul 15 08:10:13 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700
----------------------------------------------------------------------
.../org/apache/drill/exec/dotdrill/View.java | 18 +++++++-
.../exec/planner/logical/DrillViewTable.java | 4 +-
.../exec/planner/sql/handlers/ViewHandler.java | 13 +++++-
.../org/apache/drill/jdbc/test/TestViews.java | 43 +++++++++++++++++++-
4 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/7e561def/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java b/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
index 5a7c0f8..ef55d68 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
@@ -19,6 +19,7 @@ package org.apache.drill.exec.dotdrill;
import java.util.List;
+import com.google.common.collect.ImmutableList;
import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
import org.apache.drill.exec.planner.types.RelDataTypeHolder;
import org.eigenbase.reltype.RelDataType;
@@ -41,6 +42,9 @@ public class View {
private String sql;
private List<FieldType> fields;
+ /* Current schema when view is created (not the schema to which view belongs to) */
+ private List<String> workspaceSchemaPath;
+
@JsonInclude(Include.NON_NULL)
public static class FieldType {
public final String name;
@@ -80,20 +84,27 @@ public class View {
}
}
- public View(String name, String sql, RelDataType rowType){
+ public View(String name, String sql, RelDataType rowType, List<String> workspaceSchemaPath){
this.name = name;
this.sql = sql;
fields = Lists.newArrayList();
for(RelDataTypeField f : rowType.getFieldList()){
fields.add(new FieldType(f.getName(), f.getType()));
}
+ this.workspaceSchemaPath =
+ workspaceSchemaPath == null ? ImmutableList.<String>of() : ImmutableList.copyOf(workspaceSchemaPath);
}
@JsonCreator
- public View(@JsonProperty("name") String name, @JsonProperty("sql") String sql, @JsonProperty("fields") List<FieldType> fields){
+ public View(@JsonProperty("name") String name,
+ @JsonProperty("sql") String sql,
+ @JsonProperty("fields") List<FieldType> fields,
+ @JsonProperty("workspaceSchemaPath") List<String> workspaceSchemaPath){
this.name = name;
this.sql = sql;
this.fields = fields;
+ this.workspaceSchemaPath =
+ workspaceSchemaPath == null ? ImmutableList.<String>of() : ImmutableList.copyOf(workspaceSchemaPath);
}
public RelDataType getRowType(RelDataTypeFactory factory){
@@ -140,6 +151,9 @@ public class View {
return fields;
}
+ public List<String> getWorkspaceSchemaPath() {
+ return workspaceSchemaPath;
+ }
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/7e561def/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
index 19fd7ba..e798d4e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
@@ -36,11 +36,9 @@ public class DrillViewTable implements TranslatableTable, DrillViewInfoProvider
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillViewTable.class);
private final View view;
- private final List<String> path;
public DrillViewTable(List<String> path, View view){
this.view = view;
- this.path = path;
}
@Override
@@ -56,7 +54,7 @@ public class DrillViewTable implements TranslatableTable, DrillViewInfoProvider
@Override
public RelNode toRel(ToRelContext context, RelOptTable relOptTable) {
RelDataType rowType = relOptTable.getRowType();
- RelNode rel = context.expandView(rowType, view.getSql(), path);
+ RelNode rel = context.expandView(rowType, view.getSql(), view.getWorkspaceSchemaPath());
if (view.isDynamic()){
return rel;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/7e561def/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
index ced07e5..ba70ae5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
@@ -20,6 +20,8 @@ package org.apache.drill.exec.planner.sql.handlers;
import java.io.IOException;
import java.util.List;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.Table;
import net.hydromatic.optiq.impl.ViewTable;
@@ -64,7 +66,8 @@ public abstract class ViewHandler extends AbstractSqlHandler{
SqlCreateView createView = unwrap(sqlNode, SqlCreateView.class);
try {
- SchemaPlus schema = findSchema(context.getRootSchema(), context.getNewDefaultSchema(), createView.getSchemaPath());
+ SchemaPlus defaultSchema = context.getNewDefaultSchema();
+ SchemaPlus schema = findSchema(context.getRootSchema(), defaultSchema, createView.getSchemaPath());
AbstractSchema drillSchema = getDrillSchema(schema);
String schemaPath = drillSchema.getFullSchemaName();
@@ -72,6 +75,12 @@ public abstract class ViewHandler extends AbstractSqlHandler{
return DirectPlan.createDirectPlan(context, false, String.format("Current schema '%s' is not a mutable schema. " +
"Can't create views in this schema.", schemaPath));
+ // find current workspace schema path
+ List<String> workspaceSchemaPath = ImmutableList.of();
+ if (!isRootSchema(defaultSchema)) {
+ workspaceSchemaPath = getDrillSchema(defaultSchema).getSchemaPath();
+ }
+
String viewSql = createView.getQuery().toString();
SqlNode validatedQuery = planner.validate(createView.getQuery());
@@ -97,7 +106,7 @@ public abstract class ViewHandler extends AbstractSqlHandler{
queryRowType = new DrillFixedRelDataTypeImpl(planner.getTypeFactory(), viewFieldNames);
}
- View view = new View(createView.getName(), viewSql, queryRowType);
+ View view = new View(createView.getName(), viewSql, queryRowType, workspaceSchemaPath);
boolean replaced;
if (drillSchema instanceof WorkspaceSchema) {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/7e561def/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index d21b56e..89d9573 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -369,8 +369,6 @@ public class TestViews extends JdbcTestQueryBase {
statement.executeQuery("drop view dfs_test.tmp.testview").close();
- statement.executeQuery("drop view dfs_test.tmp.testview").close();
-
statement.close();
return null;
} catch (Exception e) {
@@ -424,4 +422,45 @@ public class TestViews extends JdbcTestQueryBase {
}
});
}
+
+ @Test
+ public void testViewResolvingTablesInWorkspaceSchema() throws Exception{
+ JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ Statement statement = connection.createStatement();
+
+ // change default schema
+ statement.executeQuery("USE cp");
+
+ // create a view with full schema identifier
+ ResultSet resultSet = statement.executeQuery(
+ "CREATE VIEW dfs_test.tmp.testViewResolvingTablesInWorkspaceSchema AS " +
+ "SELECT region_id, sales_city FROM `region.json`");
+ String result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ String expected = "ok=true; summary=View 'testViewResolvingTablesInWorkspaceSchema' " +
+ "created successfully in 'dfs_test.tmp' schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ // query from view
+ resultSet = statement.executeQuery(
+ "SELECT region_id FROM dfs_test.tmp.testViewResolvingTablesInWorkspaceSchema LIMIT 1");
+ result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ expected = "region_id=0";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ statement.executeQuery("drop view dfs_test.tmp.testViewResolvingTablesInWorkspaceSchema").close();
+
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
}
[03/17] git commit: DRILL-979: For Union-All don't do final column
re-ordering since the ordering is already decided by the left input of the
Union.
Posted by ja...@apache.org.
DRILL-979: For Union-All don't do final column re-ordering since the ordering is already decided by the left input of the Union.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/19dbb023
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/19dbb023
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/19dbb023
Branch: refs/heads/master
Commit: 19dbb02361cea87f679a9b65abfecc6d5541aff0
Parents: 1fb5840
Author: Aman Sinha <as...@maprtech.com>
Authored: Sun Jul 13 17:16:53 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:27:21 2014 -0700
----------------------------------------------------------------------
.../drill/exec/planner/physical/AggPrelBase.java | 5 +++++
.../exec/planner/physical/ComplexToJsonPrel.java | 5 +++++
.../drill/exec/planner/physical/FilterPrel.java | 5 +++++
.../apache/drill/exec/planner/physical/JoinPrel.java | 5 +++++
.../drill/exec/planner/physical/LimitPrel.java | 5 +++++
.../org/apache/drill/exec/planner/physical/Prel.java | 1 +
.../exec/planner/physical/ProducerConsumerPrel.java | 6 ++++++
.../drill/exec/planner/physical/ProjectPrel.java | 6 +++++-
.../apache/drill/exec/planner/physical/ScanPrel.java | 4 ++++
.../drill/exec/planner/physical/ScreenPrel.java | 5 +++++
.../drill/exec/planner/physical/SinglePrel.java | 4 ++++
.../apache/drill/exec/planner/physical/SortPrel.java | 6 ++++++
.../drill/exec/planner/physical/UnionPrel.java | 5 +++++
.../drill/exec/planner/physical/WriterPrel.java | 7 ++++++-
.../physical/visitor/FinalColumnReorderer.java | 5 +++++
.../src/test/java/org/apache/drill/TestUnionAll.java | 15 +++++++--------
16 files changed, 79 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java
index 0a3fde8..3a16414 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java
@@ -185,5 +185,10 @@ public abstract class AggPrelBase extends AggregateRelBase implements Prel{
public <T, X, E extends Throwable> T accept(PrelVisitor<T, X, E> logicalVisitor, X value) throws E {
return logicalVisitor.visitPrel(this, value);
}
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ComplexToJsonPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ComplexToJsonPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ComplexToJsonPrel.java
index b6bedb6..35e8278 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ComplexToJsonPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ComplexToJsonPrel.java
@@ -66,4 +66,9 @@ public class ComplexToJsonPrel extends SingleRel implements Prel {
return logicalVisitor.visitPrel(this, value);
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/FilterPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/FilterPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/FilterPrel.java
index c857261..337a15f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/FilterPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/FilterPrel.java
@@ -82,4 +82,9 @@ public class FilterPrel extends DrillFilterRelBase implements Prel {
return SelectionVectorMode.TWO_BYTE;
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/JoinPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/JoinPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/JoinPrel.java
index 0db9a97..cf996dc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/JoinPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/JoinPrel.java
@@ -96,4 +96,9 @@ public abstract class JoinPrel extends DrillJoinRelBase implements Prel{
return proj;
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/LimitPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/LimitPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/LimitPrel.java
index 7fad0d9..a4bb503 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/LimitPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/LimitPrel.java
@@ -89,6 +89,11 @@ public class LimitPrel extends DrillLimitRelBase implements Prel {
return SelectionVectorMode.TWO_BYTE;
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
// @Override
// public LogicalOperator implement(DrillImplementor implementor) {
// LogicalOperator inputOp = implementor.visitChild(this, 0, getChild());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/Prel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/Prel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/Prel.java
index a27626a..9286bb3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/Prel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/Prel.java
@@ -36,5 +36,6 @@ public interface Prel extends DrillRelNode, Iterable<Prel>{
public SelectionVectorMode[] getSupportedEncodings();
public SelectionVectorMode getEncoding();
+ boolean needsFinalColumnReordering();
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProducerConsumerPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProducerConsumerPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProducerConsumerPrel.java
index 35aebdc..6903767 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProducerConsumerPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProducerConsumerPrel.java
@@ -75,4 +75,10 @@ public class ProducerConsumerPrel extends SingleRel implements DrillRelNode, Pre
public SelectionVectorMode getEncoding() {
return SelectionVectorMode.NONE;
}
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
index 5280469..ae21c2c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrel.java
@@ -81,5 +81,9 @@ public class ProjectPrel extends DrillProjectRelBase implements Prel{
return SelectionVectorMode.NONE;
}
-
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return false;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java
index fc62331..e65c110 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScanPrel.java
@@ -147,4 +147,8 @@ public class ScanPrel extends AbstractRelNode implements DrillScanPrel {
return SelectionVectorMode.NONE;
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScreenPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScreenPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScreenPrel.java
index c713d7c..1a4da8a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScreenPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ScreenPrel.java
@@ -74,5 +74,10 @@ public class ScreenPrel extends DrillScreenRelBase implements Prel {
public SelectionVectorMode getEncoding() {
return SelectionVectorMode.NONE;
}
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SinglePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SinglePrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SinglePrel.java
index c23e2a1..3199943 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SinglePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SinglePrel.java
@@ -48,4 +48,8 @@ public abstract class SinglePrel extends SingleRel implements Prel{
return SelectionVectorMode.DEFAULT;
}
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SortPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SortPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SortPrel.java
index 2a8c7cf..3ef33ae 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SortPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SortPrel.java
@@ -105,4 +105,10 @@ public class SortPrel extends SortRel implements Prel {
public SelectionVectorMode getEncoding() {
return SelectionVectorMode.FOUR_BYTE;
}
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionPrel.java
index cade2df..dd1d018 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionPrel.java
@@ -44,5 +44,10 @@ public abstract class UnionPrel extends DrillUnionRelBase implements Prel{
public Iterator<Prel> iterator() {
return PrelUtil.iter(this.getInputs());
}
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WriterPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WriterPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WriterPrel.java
index d4d135c..d9db36e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WriterPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WriterPrel.java
@@ -77,5 +77,10 @@ public class WriterPrel extends DrillWriterRelBase implements Prel {
public SelectionVectorMode getEncoding() {
return SelectionVectorMode.NONE;
}
-
+
+ @Override
+ public boolean needsFinalColumnReordering() {
+ return true;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
index 4ea82cd..85f5ba3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
@@ -47,6 +47,11 @@ public class FinalColumnReorderer extends BasePrelVisitor<Prel, Void, RuntimeExc
}
private Prel addTrivialOrderedProjectPrel(Prel prel){
+
+ if ( !prel.needsFinalColumnReordering()) {
+ return prel;
+ }
+
RelDataType t = prel.getRowType();
RexBuilder b = prel.getCluster().getRexBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/19dbb023/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
index 4cb6c3e..c21298e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
@@ -23,11 +23,6 @@ import org.junit.Test;
public class TestUnionAll extends BaseTestQuery{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestUnionAll.class);
- @Test
- public void testQuery1() throws Exception {
- test("select c_name from cp.`tpch/customer.parquet` union all select c_acctbal from cp.`tpch/customer.parquet`");
- }
-
@Test // Simple Union-All over two scans
public void testUnionAll1() throws Exception {
test("select n_regionkey from cp.`tpch/nation.parquet` union all select r_regionkey from cp.`tpch/region.parquet`");
@@ -53,11 +48,15 @@ public class TestUnionAll extends BaseTestQuery{
test("select * from cp.`tpch/region.parquet` r1 union all select * from cp.`tpch/region.parquet` r2");
}
- @Test
- @Ignore // Produces wrong result
+ @Test // Union-All where same column is projected twice in right child
public void testUnionAll6() throws Exception {
test("select n_nationkey, n_regionkey from cp.`tpch/nation.parquet` where n_regionkey = 1 union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet` where r_regionkey = 2");
- }
+ }
+
+ @Test // Union-All where same column is projected twice in left and right child
+ public void testUnionAll6_1() throws Exception {
+ test("select n_nationkey, n_nationkey from cp.`tpch/nation.parquet` union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet`");
+ }
@Test // Union-all of two string literals of different lengths
public void testUnionAll7() throws Exception {
[10/17] DRILL-1155: Add option to use JDK compiler and use it for
runtime generated code over a certain threshold
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
index e785f0d..098922c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
@@ -24,9 +24,9 @@ import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocatorL;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.IdentityHashMap;
import java.util.Map;
-import java.util.Set;
+import java.util.Map.Entry;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.ExecConstants;
@@ -37,7 +37,7 @@ public class TopLevelAllocator implements BufferAllocator {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TopLevelAllocator.class);
private static final boolean ENABLE_ACCOUNTING = AssertionUtil.isAssertionsEnabled();
- private final Set<ChildAllocator> children;
+ private final Map<ChildAllocator, StackTraceElement[]> childrenMap;
private final PooledByteBufAllocator innerAllocator = PooledByteBufAllocatorL.DEFAULT;
private final Accountor acct;
private final boolean errorOnLeak;
@@ -55,7 +55,7 @@ public class TopLevelAllocator implements BufferAllocator {
private TopLevelAllocator(long maximumAllocation, boolean errorOnLeak){
this.errorOnLeak = errorOnLeak;
this.acct = new Accountor(errorOnLeak, null, null, maximumAllocation, 0);
- this.children = ENABLE_ACCOUNTING ? new HashSet<ChildAllocator>() : null;
+ this.childrenMap = ENABLE_ACCOUNTING ? new IdentityHashMap<ChildAllocator, StackTraceElement[]>() : null;
}
public TopLevelAllocator(DrillConfig config) {
@@ -99,16 +99,24 @@ public class TopLevelAllocator implements BufferAllocator {
};
logger.debug("New child allocator with initial reservation {}", initialReservation);
ChildAllocator allocator = new ChildAllocator(handle, acct, maximumReservation, initialReservation);
- if(ENABLE_ACCOUNTING) children.add(allocator);
+ if(ENABLE_ACCOUNTING) childrenMap.put(allocator, Thread.currentThread().getStackTrace());
+
return allocator;
}
@Override
public void close() {
if (ENABLE_ACCOUNTING) {
- for (ChildAllocator child : children) {
- if (!child.isClosed()) {
- throw new IllegalStateException("Failure while trying to close allocator: Child level allocators not closed.");
+ for (Entry<ChildAllocator, StackTraceElement[]> child : childrenMap.entrySet()) {
+ if (!child.getKey().isClosed()) {
+ StringBuilder sb = new StringBuilder();
+ StackTraceElement[] elements = child.getValue();
+ for (int i = 0; i < elements.length; i++) {
+ sb.append("\t\t");
+ sb.append(elements[i]);
+ sb.append("\n");
+ }
+ throw new IllegalStateException("Failure while trying to close allocator: Child level allocators not closed. Stack trace: \n" + sb);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
index 2b4743d..659a20c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
@@ -78,7 +78,6 @@ public class FragmentContext implements Closeable {
public FragmentContext(DrillbitContext dbContext, PlanFragment fragment, UserClientConnection connection,
FunctionImplementationRegistry funcRegistry) throws OutOfMemoryException, ExecutionSetupException {
- this.loader = new QueryClassLoader(true);
this.transformer = new ClassTransformer();
this.stats = new FragmentStats(dbContext.getMetrics());
this.context = dbContext;
@@ -101,6 +100,7 @@ public class FragmentContext implements Closeable {
throw new ExecutionSetupException("Failure while reading plan options.", e);
}
this.allocator = context.getAllocator().getChildAllocator(fragment.getHandle(), fragment.getMemInitial(), fragment.getMemMax());
+ this.loader = new QueryClassLoader(sessionOptions);
}
public OptionManager getOptions(){
@@ -179,13 +179,7 @@ public class FragmentContext implements Closeable {
}
public <T> T getImplementationClass(CodeGenerator<T> cg) throws ClassTransformationException, IOException {
- long t1 = System.nanoTime();
-
- T t = transformer.getImplementationClass(this.loader, cg.getDefinition(), cg.generate(),
- cg.getMaterializedClassName());
- logger.debug("Compile time: {} millis.", (System.nanoTime() - t1) / 1000 / 1000);
- return t;
-
+ return transformer.getImplementationClass(this.loader, cg.getDefinition(), cg.generate(), cg.getMaterializedClassName());
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/FragmentOptionsManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/FragmentOptionsManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/FragmentOptionsManager.java
index 7ae189e..49d08d9 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/FragmentOptionsManager.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/FragmentOptionsManager.java
@@ -51,7 +51,7 @@ public class FragmentOptionsManager implements OptionManager{
@Override
public OptionValue getOption(String name) {
OptionValue value = options.get(name);
- if (value == null) {
+ if (value == null && systemOptions != null) {
value = systemOptions.getOption(name);
}
return value;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SessionOptionManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SessionOptionManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SessionOptionManager.java
index 993cead..b5c914e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SessionOptionManager.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SessionOptionManager.java
@@ -19,7 +19,6 @@ package org.apache.drill.exec.server.options;
import java.util.Iterator;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.drill.exec.server.options.OptionValue.OptionType;
import org.eigenbase.sql.SqlLiteral;
@@ -46,7 +45,7 @@ public class SessionOptionManager implements OptionManager{
@Override
public OptionValue getOption(String name) {
OptionValue opt = options.get(name);
- if(opt == null){
+ if(opt == null && systemOptions != null){
return systemOptions.getOption(name);
}else{
return opt;
@@ -59,7 +58,6 @@ public class SessionOptionManager implements OptionManager{
setValidatedOption(value);
}
-
@Override
public OptionList getSessionOptionList() {
OptionList list = new OptionList();
@@ -94,5 +92,4 @@ public class SessionOptionManager implements OptionManager{
return systemOptions;
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
index 802f4d9..48f0df0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.cache.DistributedCache.CacheConfig;
+import org.apache.drill.exec.compile.QueryClassLoader;
import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
import org.apache.drill.exec.planner.physical.PlannerSettings;
import org.apache.drill.exec.server.options.OptionValue.OptionType;
@@ -69,7 +70,9 @@ public class SystemOptionManager implements OptionManager{
ExecConstants.QUEUE_TIMEOUT,
ExecConstants.SMALL_QUEUE_SIZE,
ExecConstants.MIN_HASH_TABLE_SIZE,
- ExecConstants.MAX_HASH_TABLE_SIZE
+ ExecConstants.MAX_HASH_TABLE_SIZE,
+ QueryClassLoader.JAVA_COMPILER_VALIDATOR,
+ QueryClassLoader.JAVA_COMPILER_JANINO_MAXSIZE
};
public final PStoreConfig<OptionValue> config;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/work/fragment/FragmentExecutor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/fragment/FragmentExecutor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/fragment/FragmentExecutor.java
index 7d4b657..51421a7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/work/fragment/FragmentExecutor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/fragment/FragmentExecutor.java
@@ -122,6 +122,7 @@ public class FragmentExecutor implements Runnable, CancelableQuery, StatusProvid
Thread.currentThread().setName(originalThread);
if(!closed) {
try {
+ root.stop();
if(context.isFailed()) {
internalFail(context.getFailureCause());
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index 07a2075..5acb596 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -64,7 +64,7 @@ public class BaseTestQuery extends ExecTest{
@SuppressWarnings("serial")
private static final Properties TEST_CONFIGURATIONS = new Properties() {
{
- put("drill.exec.sys.store.provider.local.write", "false");
+ put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, "false");
}
};
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
index dd2c91e..beac02f 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestClassTransformation.java
@@ -17,32 +17,59 @@
*/
package org.apache.drill.exec.compile;
+import org.apache.drill.BaseTestQuery;
import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.compile.sig.GeneratorMapping;
import org.apache.drill.exec.compile.sig.MappingSet;
-import org.apache.drill.exec.expr.CodeGenerator;
import org.apache.drill.exec.expr.ClassGenerator;
+import org.apache.drill.exec.expr.CodeGenerator;
import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
+import org.apache.drill.exec.server.options.OptionManager;
+import org.apache.drill.exec.server.options.OptionValue;
+import org.apache.drill.exec.server.options.OptionValue.OptionType;
+import org.apache.drill.exec.server.options.SessionOptionManager;
+import org.junit.BeforeClass;
import org.junit.Test;
-public class TestClassTransformation extends ExecTest{
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestClassTransformation.class);
+public class TestClassTransformation extends BaseTestQuery {
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestClassTransformation.class);
+
+ private static final int ITERATION_COUNT = 1;
+
+ private static SessionOptionManager sessionOptions;
+ @BeforeClass
+ public static void beforeTestClassTransformation() throws Exception {
+ sessionOptions = new SessionOptionManager(bit.getContext().getOptionManager());
+ }
+ @Test
+ public void testJaninoClassCompiler() throws Exception {
+ logger.debug("Testing JaninoClassCompiler");
+ sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, QueryClassLoader.JAVA_COMPILER_OPTION, QueryClassLoader.CompilerPolicy.JANINO.name()));
+ QueryClassLoader loader = new QueryClassLoader(sessionOptions);
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ compilationInnerClass(loader);
+ }
+ }
+ @Test
+ public void testJDKClassCompiler() throws Exception {
+ logger.debug("Testing JDKClassCompiler");
+ sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, QueryClassLoader.JAVA_COMPILER_OPTION, QueryClassLoader.CompilerPolicy.JDK.name()));
+ QueryClassLoader loader = new QueryClassLoader(sessionOptions);
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ compilationInnerClass(loader);
+ }
+ }
/**
* Do a test of a three level class to ensure that nested code generators works correctly.
* @throws Exception
*/
- @Test
- public void testInnerClassCompilation() throws Exception{
+ public void compilationInnerClass(QueryClassLoader loader) throws Exception{
final TemplateClassDefinition<ExampleInner> template = new TemplateClassDefinition<>(ExampleInner.class, ExampleTemplateWithInner.class);
-
- ClassTransformer ct = new ClassTransformer();
- QueryClassLoader loader = new QueryClassLoader(true);
- CodeGenerator<ExampleInner> cg = CodeGenerator.get(template, new FunctionImplementationRegistry(DrillConfig.create()));
+ CodeGenerator<ExampleInner> cg = CodeGenerator.get(template, bit.getContext().getFunctionImplementationRegistry());
ClassGenerator<ExampleInner> root = cg.getRoot();
root.setMappingSet(new MappingSet(new GeneratorMapping("doOutside", null, null, null)));
@@ -57,9 +84,11 @@ public class TestClassTransformation extends ExecTest{
doubleInner.setMappingSet(new MappingSet(new GeneratorMapping("doDouble", null, null, null)));
doubleInner.getSetupBlock().directStatement("System.out.println(\"double\");");
+ ClassTransformer ct = new ClassTransformer();
ExampleInner t = ct.getImplementationClass(loader, cg.getDefinition(), cg.generate(), cg.getMaterializedClassName());
+
t.doOutside();
t.doInsideOutside();
-
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestLargeFileCompilation.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestLargeFileCompilation.java b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestLargeFileCompilation.java
new file mode 100644
index 0000000..fecf66b
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/compile/TestLargeFileCompilation.java
@@ -0,0 +1,63 @@
+/**
+ * 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.compile;
+
+import java.util.List;
+
+import org.apache.drill.BaseTestQuery;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryResultBatch;
+import org.junit.Test;
+
+public class TestLargeFileCompilation extends BaseTestQuery {
+
+ private static final String LARGE_QUERY;
+
+ private static final int ITERATION_COUNT = 1;
+
+ static {
+ StringBuilder sb = new StringBuilder("select \n");
+ for (int i = 0; i < 300; i++) {
+ sb.append("\temployee_id+").append(i).append(" as col").append(i).append(",\n");
+ }
+ sb.append("\tfull_name\nfrom cp.`employee.json` limit 1");
+ LARGE_QUERY = sb.toString();
+ }
+
+ @Test
+ public void testWithJDK() throws Exception {
+ test(String.format("alter session set `%s`='JDK'", QueryClassLoader.JAVA_COMPILER_OPTION));
+ runTest();
+ }
+
+ @Test(expected=org.apache.drill.exec.rpc.RpcException.class)
+ public void testWithJanino() throws Exception {
+ test(String.format("alter session set `%s`='JANINO'", QueryClassLoader.JAVA_COMPILER_OPTION));
+ runTest();
+ }
+
+ private void runTest() throws Exception {
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ List<QueryResultBatch> results = client.runQuery(QueryType.SQL, LARGE_QUERY);
+ for (QueryResultBatch queryResultBatch : results) {
+ queryResultBatch.release();
+ }
+ }
+ }
+
+}
[16/17] git commit: DRILL-1143: Enable project pushdown into
HiveRecordReader
Posted by ja...@apache.org.
DRILL-1143: Enable project pushdown into HiveRecordReader
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/111c1a8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/111c1a8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/111c1a8a
Branch: refs/heads/master
Commit: 111c1a8adf537e8f368de96c4be4c73327451202
Parents: 65c8358
Author: vkorukanti <ve...@gmail.com>
Authored: Tue Jun 17 17:56:45 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700
----------------------------------------------------------------------
.../drill/exec/store/hive/HiveRecordReader.java | 2 +-
.../apache/drill/exec/store/hive/HiveScan.java | 11 ++-
.../exec/store/hive/HiveStoragePlugin.java | 2 +-
.../drill/exec/TestHiveProjectPushDown.java | 91 ++++++++++++++++++++
.../exec/store/hive/HiveTestDataGenerator.java | 21 ++++-
.../java/org/apache/drill/BaseTestQuery.java | 4 +
6 files changed, 125 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
index ddb08c6..8a84ac2 100644
--- a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
+++ b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveRecordReader.java
@@ -169,7 +169,7 @@ public class HiveRecordReader implements RecordReader {
List<Integer> columnIds = Lists.newArrayList();
selectedColumnNames = Lists.newArrayList();
for (SchemaPath field : projectedColumns) {
- String columnName = field.getRootSegment().getPath(); //TODO?
+ String columnName = field.getRootSegment().getPath();
if (!tableColumns.contains(columnName)) {
if (partitionNames.contains(columnName)) {
selectedPartitionNames.add(columnName);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveScan.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveScan.java b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveScan.java
index 8c02eb3..61b6c7f 100644
--- a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveScan.java
+++ b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveScan.java
@@ -89,9 +89,10 @@ public class HiveScan extends AbstractGroupScan {
Map<InputSplit, Partition> partitionMap = new HashMap();
@JsonCreator
- public HiveScan(@JsonProperty("hive-table") HiveReadEntry hiveReadEntry, @JsonProperty("storage-plugin") String storagePluginName,
- @JsonProperty("columns") List<SchemaPath> columns,
- @JacksonInject StoragePluginRegistry pluginRegistry) throws ExecutionSetupException {
+ public HiveScan(@JsonProperty("hive-table") HiveReadEntry hiveReadEntry,
+ @JsonProperty("storage-plugin") String storagePluginName,
+ @JsonProperty("columns") List<SchemaPath> columns,
+ @JacksonInject StoragePluginRegistry pluginRegistry) throws ExecutionSetupException {
this.hiveReadEntry = hiveReadEntry;
this.table = hiveReadEntry.getTable();
this.storagePluginName = storagePluginName;
@@ -300,4 +301,8 @@ public class HiveScan extends AbstractGroupScan {
return newScan;
}
+ @Override
+ public boolean canPushdownProjects(List<SchemaPath> columns) {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
index c5a6e2c..da8a41a 100644
--- a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
+++ b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
@@ -72,7 +72,7 @@ public class HiveStoragePlugin extends AbstractStoragePlugin {
throw new UnsupportedOperationException("Querying Hive views from Drill is not supported in current version.");
}
- return new HiveScan(hiveReadEntry, this, null);
+ return new HiveScan(hiveReadEntry, this, columns);
} catch (ExecutionSetupException e) {
throw new IOException(e);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/TestHiveProjectPushDown.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/TestHiveProjectPushDown.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/TestHiveProjectPushDown.java
new file mode 100644
index 0000000..6ced636
--- /dev/null
+++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/TestHiveProjectPushDown.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec;
+
+import org.apache.drill.PlanTestBase;
+import org.apache.drill.exec.store.hive.HiveTestDataGenerator;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestHiveProjectPushDown extends PlanTestBase {
+
+ @BeforeClass
+ public static void generateHive() throws Exception{
+ new HiveTestDataGenerator().createAndAddHiveTestPlugin(bit.getContext().getStorage());
+ }
+
+ private void testHelper(String query, String expectedColNamesInPlan, int expectedRecordCount)throws Exception {
+ testPhysicalPlan(query, expectedColNamesInPlan);
+
+ int actualRecordCount = testSql(query);
+ assertEquals(String.format("Received unexepcted number of rows in output: expected=%d, received=%s",
+ expectedRecordCount, actualRecordCount), expectedRecordCount, actualRecordCount);
+ }
+
+ @Test
+ public void testSingleColumnProject() throws Exception {
+ String query = "SELECT `value` as v FROM hive.`default`.kv";
+ String expectedColNames = " \"columns\" : [ \"`value`\" ]";
+
+ testHelper(query, expectedColNames, 5);
+ }
+
+ @Test
+ public void testMultipleColumnsProject() throws Exception {
+ String query = "SELECT boolean_field as b_f, tinyint_field as ti_f FROM hive.`default`.readtest";
+ String expectedColNames = " \"columns\" : [ \"`boolean_field`\", \"`tinyint_field`\" ]";
+
+ testHelper(query, expectedColNames, 1);
+ }
+
+ @Test
+ public void testPartitionColumnProject() throws Exception {
+ String query = "SELECT double_part as dbl_p FROM hive.`default`.readtest";
+ String expectedColNames = " \"columns\" : [ \"`double_part`\" ]";
+
+ testHelper(query, expectedColNames, 1);
+ }
+
+ @Test
+ public void testMultiplePartitionColumnsProject() throws Exception {
+ String query = "SELECT double_part as dbl_p, decimal_part as dec_p FROM hive.`default`.readtest";
+ String expectedColNames = " \"columns\" : [ \"`double_part`\", \"`decimal_part`\" ]";
+
+ testHelper(query, expectedColNames, 1);
+ }
+
+ @Test
+ public void testPartitionAndRegularColumnProjectColumn() throws Exception {
+ String query = "SELECT boolean_field as b_f, tinyint_field as ti_f, " +
+ "double_part as dbl_p, decimal_part as dec_p FROM hive.`default`.readtest";
+ String expectedColNames = " \"columns\" : [ \"`boolean_field`\", \"`tinyint_field`\", " +
+ "\"`double_part`\", \"`decimal_part`\" ]";
+
+ testHelper(query, expectedColNames, 1);
+ }
+
+ @Test
+ public void testStarProject() throws Exception {
+ String query = "SELECT * FROM hive.`default`.kv";
+ String expectedColNames = " \"columns\" : [ \"`key`\", \"`value`\" ]";
+
+ testHelper(query, expectedColNames, 5);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java
index 3fe36f5..adb007d 100644
--- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java
+++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/HiveTestDataGenerator.java
@@ -23,8 +23,11 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.Timestamp;
+import java.util.Map;
+import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
+import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.CommandNeedRetryException;
@@ -52,7 +55,23 @@ public class HiveTestDataGenerator {
FileUtils.forceDelete(f);
}
}
-
+
+ public void createAndAddHiveTestPlugin(StoragePluginRegistry pluginRegistry) throws Exception {
+ // generate test tables and data
+ generateTestData();
+
+ // add Hive plugin to given registry
+ Map<String, String> config = Maps.newHashMap();
+ config.put("hive.metastore.uris", "");
+ config.put("javax.jdo.option.ConnectionURL", String.format("jdbc:derby:;databaseName=%s;create=true", DB_DIR));
+ config.put("hive.metastore.warehouse.dir", WH_DIR);
+ config.put("fs.default.name", "file:///");
+ HiveStoragePluginConfig pluginConfig = new HiveStoragePluginConfig(config);
+ pluginConfig.setEnabled(true);
+
+ pluginRegistry.createOrUpdate("hive", pluginConfig, true);
+ }
+
public void generateTestData() throws Exception {
// remove data from previous runs.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/111c1a8a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index 5acb596..b1c1ec8 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -175,6 +175,10 @@ public class BaseTestQuery extends ExecTest{
return testRunAndPrint(QueryType.PHYSICAL, query);
}
+ protected int testSql(String query) throws Exception{
+ return testRunAndPrint(QueryType.SQL, query);
+ }
+
protected void testPhysicalFromFile(String file) throws Exception{
testPhysical(getFile(file));
}
[11/17] git commit: DRILL-1155: Add option to use JDK compiler and
use it for runtime generated code over a certain threshold
Posted by ja...@apache.org.
DRILL-1155: Add option to use JDK compiler and use it for runtime generated code over a certain threshold
+ Updating Janino to 2.7.4 (from 2.6.1).
+ Added session options `exec.java_compiler`:[DEFAULT, JDK, JANINO] and `exec.java_compiler_janino_maxsize`(256k).
+ Fix a bug in FragmentExecutor.java(125) where the root operator is not stopped in case of fragment failure.
+ Print Java stack trace of the allocator code if a TLA detects that any of the ChildAllocator is not closed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/02f1c82d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/02f1c82d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/02f1c82d
Branch: refs/heads/master
Commit: 02f1c82d8d7c87ed416a19b7a13463fdbffeb86d
Parents: 2beeda0
Author: Aditya Kishore <ad...@maprtech.com>
Authored: Thu Jul 10 01:31:39 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:32:59 2014 -0700
----------------------------------------------------------------------
.../apache/drill/common/config/DrillConfig.java | 3 +
.../drill/common/util/DrillStringUtils.java | 14 +
.../java/org/apache/drill/test/DrillTest.java | 16 +-
exec/java-exec/pom.xml | 7 +-
.../exec/compile/AbstractClassCompiler.java | 75 ++
.../drill/exec/compile/ClassCompiler.java | 3 +-
.../drill/exec/compile/ClassTransformer.java | 100 +-
.../exec/compile/DrillDiagnosticListener.java | 49 +
.../exec/compile/DrillJavaFileManager.java | 69 ++
.../drill/exec/compile/DrillJavaFileObject.java | 109 +++
.../drill/exec/compile/JDKClassCompiler.java | 96 ++
.../drill/exec/compile/JaninoClassCompiler.java | 47 +-
.../drill/exec/compile/QueryClassLoader.java | 93 +-
.../exec/expr/fn/ModifiedUnparseVisitor.java | 976 ++-----------------
.../drill/exec/memory/TopLevelAllocator.java | 24 +-
.../apache/drill/exec/ops/FragmentContext.java | 10 +-
.../server/options/FragmentOptionsManager.java | 2 +-
.../server/options/SessionOptionManager.java | 5 +-
.../server/options/SystemOptionManager.java | 5 +-
.../exec/work/fragment/FragmentExecutor.java | 1 +
.../java/org/apache/drill/BaseTestQuery.java | 2 +-
.../exec/compile/TestClassTransformation.java | 51 +-
.../exec/compile/TestLargeFileCompilation.java | 63 ++
23 files changed, 773 insertions(+), 1047 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
index 2455dd9..0b2b22d 100644
--- a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
+++ b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
@@ -122,6 +122,9 @@ public final class DrillConfig extends NestedConfig{
return create(overrideFileName, true);
}
+ /**
+ * <b><u>Do not use this method outside of test code.</u></b>
+ */
@VisibleForTesting
public static DrillConfig create(Properties testConfigurations) {
return create(null, testConfigurations, true);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/common/src/main/java/org/apache/drill/common/util/DrillStringUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/util/DrillStringUtils.java b/common/src/main/java/org/apache/drill/common/util/DrillStringUtils.java
index 96b5776..c23424e 100644
--- a/common/src/main/java/org/apache/drill/common/util/DrillStringUtils.java
+++ b/common/src/main/java/org/apache/drill/common/util/DrillStringUtils.java
@@ -22,6 +22,20 @@ import org.apache.commons.lang3.StringEscapeUtils;
import io.netty.buffer.ByteBuf;
public class DrillStringUtils {
+
+ /**
+ * Converts the long number into more human readable string.
+ */
+ public static String readable(long bytes) {
+ int unit = 1024;
+ long absBytes = Math.abs(bytes);
+ if (absBytes < unit) return bytes + " B";
+ int exp = (int) (Math.log(absBytes) / Math.log(unit));
+ char pre = ("KMGTPE").charAt(exp-1);
+ return String.format("%s%.1f %ciB", (bytes == absBytes ? "" : "-"), absBytes / Math.pow(unit, exp), pre);
+ }
+
+
/**
* Unescapes any Java literals found in the {@code String}.
* For example, it will turn a sequence of {@code '\'} and
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/common/src/test/java/org/apache/drill/test/DrillTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/test/DrillTest.java b/common/src/test/java/org/apache/drill/test/DrillTest.java
index 6716f83..55f89b3 100644
--- a/common/src/test/java/org/apache/drill/test/DrillTest.java
+++ b/common/src/test/java/org/apache/drill/test/DrillTest.java
@@ -22,6 +22,7 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.List;
+import org.apache.drill.common.util.DrillStringUtils;
import org.apache.drill.common.util.TestTools;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -84,9 +85,9 @@ public class DrillTest {
long endHeap = manager.getMemHeap();
long endNonHeap = manager.getMemNonHeap();
return String.format("d: %s(%s), h: %s(%s), nh: %s(%s)", //
- readable(endDirect - startDirect), readable(endDirect), //
- readable(endHeap - startHeap), readable(endHeap), //
- readable(endNonHeap - startNonHeap), readable(endNonHeap) //
+ DrillStringUtils.readable(endDirect - startDirect), DrillStringUtils.readable(endDirect), //
+ DrillStringUtils.readable(endHeap - startHeap), DrillStringUtils.readable(endHeap), //
+ DrillStringUtils.readable(endNonHeap - startNonHeap), DrillStringUtils.readable(endNonHeap) //
);
}
@@ -135,15 +136,6 @@ public class DrillTest {
}
}
- public static String readable(long bytes) {
- int unit = 1024;
- long absBytes = Math.abs(bytes);
- if (absBytes < unit) return bytes + " B";
- int exp = (int) (Math.log(absBytes) / Math.log(unit));
- char pre = ("KMGTPE").charAt(exp-1);
- return String.format("%s%.1f %ciB", (bytes == absBytes ? "" : "-"), absBytes / Math.pow(unit, exp), pre);
- }
-
private static class SystemManager {
final BufferPoolMXBean directBean;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/pom.xml
----------------------------------------------------------------------
diff --git a/exec/java-exec/pom.xml b/exec/java-exec/pom.xml
index 0516967..30dff55 100644
--- a/exec/java-exec/pom.xml
+++ b/exec/java-exec/pom.xml
@@ -237,7 +237,12 @@
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
- <version>2.6.1</version>
+ <version>2.7.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.janino</groupId>
+ <artifactId>commons-compiler-jdk</artifactId>
+ <version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/AbstractClassCompiler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/AbstractClassCompiler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/AbstractClassCompiler.java
new file mode 100644
index 0000000..91588b8
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/AbstractClassCompiler.java
@@ -0,0 +1,75 @@
+/**
+ * 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.compile;
+
+import java.io.IOException;
+
+import org.apache.drill.common.util.DrillStringUtils;
+import org.apache.drill.exec.compile.ClassTransformer.ClassNames;
+import org.apache.drill.exec.exception.ClassTransformationException;
+import org.codehaus.commons.compiler.CompileException;
+
+public abstract class AbstractClassCompiler implements ClassCompiler {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractClassCompiler.class);
+
+ protected boolean debugLines = true;
+ protected boolean debugVars = true;
+ protected boolean debugSource = true;
+
+ protected abstract byte[][] getByteCode(ClassNames className, String sourcecode)
+ throws CompileException, IOException, ClassNotFoundException, ClassTransformationException;
+
+ @Override
+ public byte[][] getClassByteCode(ClassNames className, String sourceCode)
+ throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Compiling (source size={}):\n{}", DrillStringUtils.readable(sourceCode.length()), prefixLineNumbers(sourceCode));
+ }
+ return getByteCode(className, sourceCode);
+ }
+
+ public void setDebuggingOptions(boolean debugSource, boolean debugLines, boolean debugVars) {
+ this.debugSource = debugSource;
+ this.debugLines = debugLines;
+ this.debugVars = debugVars;
+ updateDebugOptions();
+ }
+
+ protected String prefixLineNumbers(String code) {
+ if (!debugLines) return code;
+ StringBuilder out = new StringBuilder();
+ int i = 1;
+ for (String line : code.split("\n")) {
+ int start = out.length();
+ out.append(i++);
+ int numLength = out.length() - start;
+ out.append(":");
+ for (int spaces = 0; spaces < 7 - numLength; ++spaces){
+ out.append(" ");
+ }
+ out.append(line);
+ out.append('\n');
+ }
+ return out.toString();
+ }
+
+ protected void updateDebugOptions() { } // default no-op implementation
+
+ protected org.slf4j.Logger getLogger() { return logger; }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassCompiler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassCompiler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassCompiler.java
index 36db9d7..fb080f8 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassCompiler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassCompiler.java
@@ -19,11 +19,12 @@ package org.apache.drill.exec.compile;
import java.io.IOException;
+import org.apache.drill.exec.compile.ClassTransformer.ClassNames;
import org.apache.drill.exec.exception.ClassTransformationException;
import org.codehaus.commons.compiler.CompileException;
interface ClassCompiler {
- public abstract byte[][] getClassByteCode(String className, String sourcecode) throws CompileException, IOException, ClassNotFoundException, ClassTransformationException ;
+ public abstract byte[][] getClassByteCode(ClassNames className, String sourcecode) throws CompileException, IOException, ClassNotFoundException, ClassTransformationException ;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
index 25c71b1..44ea5b5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.drill.common.util.DrillStringUtils;
import org.apache.drill.common.util.FileUtils;
import org.apache.drill.exec.compile.MergeAdapter.MergedClassResult;
import org.apache.drill.exec.exception.ClassTransformationException;
@@ -61,27 +62,27 @@ public class ClassTransformer {
//
// }
-
-
+
+
public static class ClassSet{
public final ClassSet parent;
public final ClassNames precompiled;
public final ClassNames generated;
-
+
public ClassSet(ClassSet parent, String precompiled, String generated) {
super();
this.parent = parent;
-
+
this.precompiled = new ClassNames(precompiled);
this.generated = new ClassNames(generated);
- Preconditions.checkArgument(!generated.startsWith(precompiled),
+ Preconditions.checkArgument(!generated.startsWith(precompiled),
String.format("The new name of a class cannot start with the old name of a class, otherwise class renaming will cause problems. Precompiled class name %s. Generated class name %s", precompiled, generated));
}
-
+
public ClassSet getChild(String precompiled, String generated){
return new ClassSet(this, precompiled, generated);
}
-
+
public ClassSet getChild(String precompiled){
return new ClassSet(this, precompiled, precompiled.replace(this.precompiled.dot, this.generated.dot));
}
@@ -122,16 +123,16 @@ public class ClassTransformer {
return false;
return true;
}
-
-
+
+
}
-
+
public static class ClassNames{
-
+
public final String dot;
public final String slash;
public final String clazz;
-
+
public ClassNames(String className){
dot = className;
slash = className.replace('.', FileUtils.separatorChar);
@@ -174,16 +175,16 @@ public class ClassTransformer {
return false;
return true;
}
-
-
-//
+
+
+//
// public ClassNames getFixed(ClassNames precompiled, ClassNames generated){
// if(!dot.startsWith(precompiled.dot)) throw new IllegalStateException(String.format("Expected a class that starts with %s. However the class %s does not start with this string.", precompiled.dot, dot));
// return new ClassNames(dot.replace(precompiled.dot, generated.dot));
// }
}
-
-//
+
+//
// private void mergeAndInjectClass(QueryClassLoader classLoader, byte[] implementationClass, ClassNames precompiled, ClassNames generated){
// // Get Template Class
// final byte[] templateClass = byteCodeLoader.getClassByteCodeFromPath(precompiled.clazz);
@@ -193,11 +194,11 @@ public class ClassTransformer {
//
// // Setup adapters for merging, remapping class names and class writing. This is done in reverse order of how they
// // will be evaluated.
-//
+//
// Stopwatch t3;
// {
//
-// //
+// //
// ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
//
// ClassVisitor remappingAdapter = new RemappingClassAdapter(cw, remapper);
@@ -232,15 +233,14 @@ public class ClassTransformer {
// i++;
// }
// }
-//
+//
private static ClassNode getClassNodeFromByteCode(byte[] bytes) {
ClassReader iReader = new ClassReader(bytes);
ClassNode impl = new ClassNode();
- iReader.accept(impl, 0);
+ iReader.accept(impl, ClassReader.EXPAND_FRAMES);
return impl;
}
-
@SuppressWarnings("unchecked")
public <T, I> T getImplementationClass( //
QueryClassLoader classLoader, //
@@ -248,71 +248,53 @@ public class ClassTransformer {
String entireClass, //
String materializedClassName) throws ClassTransformationException {
- final ClassSet set = new ClassSet(null, templateDefinition.getTemplateClassName(), materializedClassName);
-
-
-
try {
- final byte[][] implementationClasses = classLoader.getClassByteCode(set.generated.clazz, entireClass);
-
-
+ long t1 = System.nanoTime();
+ final ClassSet set = new ClassSet(null, templateDefinition.getTemplateClassName(), materializedClassName);
+ final byte[][] implementationClasses = classLoader.getClassByteCode(set.generated, entireClass);
+
+ long totalBytecodeSize = 0;
Map<String, ClassNode> classesToMerge = Maps.newHashMap();
- for(byte[] clazz : implementationClasses){
+ for(byte[] clazz : implementationClasses) {
+ totalBytecodeSize += clazz.length;
ClassNode node = getClassNodeFromByteCode(clazz);
classesToMerge.put(node.name, node);
}
-
+
LinkedList<ClassSet> names = Lists.newLinkedList();
Set<ClassSet> namesCompleted = Sets.newHashSet();
names.add(set);
-
- while( !names.isEmpty() ){
+
+ while ( !names.isEmpty() ) {
final ClassSet nextSet = names.removeFirst();
- if(namesCompleted.contains(nextSet)) continue;
+ if (namesCompleted.contains(nextSet)) continue;
final ClassNames nextPrecompiled = nextSet.precompiled;
final byte[] precompiledBytes = byteCodeLoader.getClassByteCodeFromPath(nextPrecompiled.clazz);
ClassNames nextGenerated = nextSet.generated;
ClassNode generatedNode = classesToMerge.get(nextGenerated.slash);
MergedClassResult result = MergeAdapter.getMergedClass(nextSet, precompiledBytes, generatedNode);
-
- for(String s : result.innerClasses){
+
+ for(String s : result.innerClasses) {
s = s.replace(FileUtils.separatorChar, '.');
names.add(nextSet.getChild(s));
}
classLoader.injectByteCode(nextGenerated.dot, result.bytes);
namesCompleted.add(nextSet);
-
}
-
-
-
-
-// logger.debug(String.format("[Compile Time] Janino: %dms, Bytecode load and parse: %dms, Class Merge: %dms, Subclass remap and load: %dms.", t1.elapsed(TimeUnit.MILLISECONDS), t2.elapsed(TimeUnit.MILLISECONDS), t3.elapsed(TimeUnit.MILLISECONDS), t4.elapsed(TimeUnit.MILLISECONDS)));
-
-
-
+
Class<?> c = classLoader.findClass(set.generated.dot);
if (templateDefinition.getExternalInterface().isAssignableFrom(c)) {
- return (T) c.newInstance();
+ T instance = (T) c.newInstance();
+ logger.debug("Done compiling (bytecode size={}, time:{} millis).",
+ DrillStringUtils.readable(totalBytecodeSize), (System.nanoTime() - t1) / 1000000);
+ return instance;
} else {
throw new ClassTransformationException("The requested class did not implement the expected interface.");
}
-
} catch (CompileException | IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
- throw new ClassTransformationException(String.format(
- "Failure generating transformation classes for value: \n %s", entireClass), e);
+ throw new ClassTransformationException(String.format("Failure generating transformation classes for value: \n %s", entireClass), e);
}
}
-
-
- // private void traceClassToSystemOut(byte[] bytecode) {
- // TraceClassVisitor tcv = new TraceClassVisitor(new EmptyVisitor(), new PrintWriter(System.out));
- // ClassReader cr = new ClassReader(bytecode);
- // cr.accept(tcv, 0);
- // }
-
-
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillDiagnosticListener.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillDiagnosticListener.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillDiagnosticListener.java
new file mode 100644
index 0000000..890243c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillDiagnosticListener.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.compile;
+
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileObject;
+
+import org.codehaus.commons.compiler.CompileException;
+import org.codehaus.commons.compiler.Location;
+
+/* package */
+final class DrillDiagnosticListener implements DiagnosticListener<JavaFileObject> {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillDiagnosticListener.class);
+
+ @Override
+ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+ if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
+ String message = diagnostic.toString() + " (" + diagnostic.getCode() + ")";
+ logger.error(message);
+ Location loc = new Location( //
+ diagnostic.getSource().toString(), //
+ (short) diagnostic.getLineNumber(), //
+ (short) diagnostic.getColumnNumber() //
+ );
+ // Wrap the exception in a RuntimeException, because "report()"
+ // does not declare checked exceptions.
+ throw new RuntimeException(new CompileException(message, loc));
+ } else if (logger.isTraceEnabled()) {
+ logger.trace(diagnostic.toString() + " (" + diagnostic.getCode() + ")");
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileManager.java
new file mode 100644
index 0000000..96d3119
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileManager.java
@@ -0,0 +1,69 @@
+/**
+ * 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.compile;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.tools.FileObject;
+import javax.tools.ForwardingJavaFileManager;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.JavaFileObject.Kind;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Sets;
+
+/* package */
+class DrillJavaFileManager extends ForwardingJavaFileManager<JavaFileManager> {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillJavaFileManager.class);
+
+ public static final Predicate<Kind> NO_SOURCES_KIND = new Predicate<Kind>() {
+ @Override
+ public boolean apply(Kind input) {
+ return input != Kind.SOURCE;
+ }
+ };
+
+ private final ClassLoader classLoader;
+
+ protected DrillJavaFileManager(JavaFileManager fileManager, ClassLoader classLoader) {
+ super(fileManager);
+ this.classLoader = classLoader;
+ }
+
+ @Override
+ public ClassLoader getClassLoader(Location location) {
+ return classLoader;
+ }
+
+ @Override
+ public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
+ return super.list(location, packageName, Sets.filter(kinds, NO_SOURCES_KIND), recurse);
+ }
+
+ @Override
+ public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
+ logger.trace("Creating JavaFileForOutput@(location:{}, className:{}, kinds:{})", location, className, kind);
+ if (sibling != null && sibling instanceof DrillJavaFileObject) {
+ return ((DrillJavaFileObject)sibling).addOutputJavaFile(className);
+ }
+ throw new IOException("The source file passed to getJavaFileForOutput() is not a DrillJavaFileObject: " + sibling);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileObject.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileObject.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileObject.java
new file mode 100644
index 0000000..024fd01
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/DrillJavaFileObject.java
@@ -0,0 +1,109 @@
+/**
+ * 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.compile;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import javax.tools.SimpleJavaFileObject;
+
+import com.google.common.collect.Maps;
+
+/* package */
+final class DrillJavaFileObject extends SimpleJavaFileObject {
+ private final String sourceCode;
+
+ private final ByteArrayOutputStream outputStream;
+
+ private Map<String, DrillJavaFileObject> outputFiles;
+
+ public DrillJavaFileObject(final String className, final String sourceCode) {
+ super(makeURI(className), Kind.SOURCE);
+ this.sourceCode = sourceCode;
+ this.outputStream = null;
+ }
+
+ private DrillJavaFileObject(final String name, final Kind kind) {
+ super(makeURI(name), kind);
+ this.outputStream = new ByteArrayOutputStream();
+ this.sourceCode = null;
+ }
+
+ public boolean isCompiled() {
+ return (outputFiles != null);
+ }
+
+ public byte[][] getByteCode() {
+ if (!isCompiled()) {
+ return null;
+ } else {
+ int index = 0;
+ byte[][] byteCode = new byte[outputFiles.size()][];
+ for(DrillJavaFileObject outputFile : outputFiles.values()) {
+ byteCode[index++] = outputFile.outputStream.toByteArray();
+ }
+ return byteCode;
+ }
+ }
+
+ public DrillJavaFileObject addOutputJavaFile(String className) {
+ if (outputFiles == null) {
+ outputFiles = Maps.newLinkedHashMap();
+ }
+ DrillJavaFileObject outputFile = new DrillJavaFileObject(className, Kind.CLASS);
+ outputFiles.put(className, outputFile);
+ return outputFile;
+ }
+
+ @Override
+ public Reader openReader(final boolean ignoreEncodingErrors) throws IOException {
+ return new StringReader(sourceCode);
+ }
+
+ @Override
+ public CharSequence getCharContent(final boolean ignoreEncodingErrors) throws IOException {
+ if (sourceCode == null)
+ throw new UnsupportedOperationException("This instance of DrillJavaFileObject is not an input object.");
+ return sourceCode;
+ }
+
+ @Override
+ public OutputStream openOutputStream() {
+ if (outputStream == null) {
+ throw new UnsupportedOperationException("This instance of DrillJavaFileObject is not an output object.");
+ }
+ return outputStream;
+ }
+
+ private static URI makeURI(final String canonicalClassName) {
+ final int dotPos = canonicalClassName.lastIndexOf('.');
+ final String simpleClassName = dotPos == -1 ? canonicalClassName : canonicalClassName.substring(dotPos + 1);
+ try {
+ return new URI(simpleClassName + Kind.SOURCE.extension);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JDKClassCompiler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JDKClassCompiler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JDKClassCompiler.java
new file mode 100644
index 0000000..2bbf4f8
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JDKClassCompiler.java
@@ -0,0 +1,96 @@
+/**
+ * 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.compile;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileObject;
+import javax.tools.ToolProvider;
+
+import org.apache.drill.exec.compile.ClassTransformer.ClassNames;
+import org.codehaus.commons.compiler.CompileException;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+
+class JDKClassCompiler extends AbstractClassCompiler {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JDKClassCompiler.class);
+
+ private Collection<String> compilerOptions;
+ private DiagnosticListener<JavaFileObject> listener;
+ private final JavaCompiler compiler;
+ private final DrillJavaFileManager fileManager;
+
+ public JDKClassCompiler(ClassLoader classLoader) {
+ this.compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ throw new UnsupportedOperationException("JDK Java compiler not available - probably you're running a JRE, not a JDK");
+ }
+ this.listener = new DrillDiagnosticListener();
+ this.fileManager = new DrillJavaFileManager(compiler.getStandardFileManager(listener, null, Charsets.UTF_8), classLoader);
+ updateDebugOptions();
+ }
+
+ @Override
+ protected byte[][] getByteCode(final ClassNames className, final String sourceCode)
+ throws CompileException, IOException, ClassNotFoundException {
+ try {
+ // Create one Java source file in memory, which will be compiled later.
+ DrillJavaFileObject compilationUnit = new DrillJavaFileObject(className.dot, sourceCode);
+
+ CompilationTask task = compiler.getTask(null, fileManager, listener, compilerOptions, null, Collections.singleton(compilationUnit));
+
+ // Run the compiler.
+ if(!task.call()) {
+ throw new CompileException("Compilation failed", null);
+ } else if (!compilationUnit.isCompiled()) {
+ throw new ClassNotFoundException(className + ": Class file not created by compilation.");
+ }
+ // all good
+ return compilationUnit.getByteCode();
+ } catch (RuntimeException rte) {
+ // Unwrap the compilation exception and throw it.
+ Throwable cause = rte.getCause();
+ if (cause != null) {
+ cause = cause.getCause();
+ if (cause instanceof CompileException) throw (CompileException) cause;
+ if (cause instanceof IOException) throw (IOException) cause;
+ }
+ throw rte;
+ }
+ }
+
+ protected void updateDebugOptions() {
+ StringBuilder sb = new StringBuilder("-g:");
+ if (this.debugSource) sb.append("source,");
+ if (this.debugLines) sb.append("lines,");
+ if (this.debugVars) sb.append("vars,");
+ if (sb.length() == 3) { // "-g:"
+ sb.append("none,");
+ }
+ compilerOptions = Lists.newArrayList(sb.substring(0, sb.length()-1));
+ }
+
+ protected org.slf4j.Logger getLogger() { return logger; }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JaninoClassCompiler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JaninoClassCompiler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JaninoClassCompiler.java
index e381e32..4b17598 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JaninoClassCompiler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/JaninoClassCompiler.java
@@ -20,6 +20,7 @@ package org.apache.drill.exec.compile;
import java.io.IOException;
import java.io.StringReader;
+import org.apache.drill.exec.compile.ClassTransformer.ClassNames;
import org.apache.drill.exec.exception.ClassTransformationException;
import org.codehaus.commons.compiler.CompileException;
import org.codehaus.janino.ClassLoaderIClassLoader;
@@ -30,58 +31,30 @@ import org.codehaus.janino.Scanner;
import org.codehaus.janino.UnitCompiler;
import org.codehaus.janino.util.ClassFile;
-public class JaninoClassCompiler implements ClassCompiler{
+public class JaninoClassCompiler extends AbstractClassCompiler {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JaninoClassCompiler.class);
private IClassLoader compilationClassLoader;
- private boolean debugLines = true;
- private boolean debugVars = true;
- private boolean debugSource = true;
-
public JaninoClassCompiler(ClassLoader parentClassLoader) {
this.compilationClassLoader = new ClassLoaderIClassLoader(parentClassLoader);
}
- public byte[][] getClassByteCode(final String className, final String code) throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
- if(logger.isDebugEnabled()){
- logger.debug("Compiling:\n{}", prefixLineNumbers(code));
- }
- StringReader reader = new StringReader(code);
+ protected byte[][] getByteCode(final ClassNames className, final String sourcecode)
+ throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
+ StringReader reader = new StringReader(sourcecode);
Scanner scanner = new Scanner((String) null, reader);
Java.CompilationUnit compilationUnit = new Parser(scanner).parseCompilationUnit();
- ClassFile[] classFiles = new UnitCompiler(compilationUnit, compilationClassLoader).compileUnit(this.debugSource,
- this.debugLines, this.debugVars);
-
+ ClassFile[] classFiles = new UnitCompiler(compilationUnit, compilationClassLoader)
+ .compileUnit(this.debugSource, this.debugLines, this.debugVars);
+
byte[][] byteCodes = new byte[classFiles.length][];
- for(int i =0; i < classFiles.length; i++){
+ for(int i = 0; i < classFiles.length; i++){
byteCodes[i] = classFiles[i].toByteArray();
}
return byteCodes;
}
+ protected org.slf4j.Logger getLogger() { return logger; }
- private String prefixLineNumbers(String code) {
- if (!debugLines) return code;
- StringBuilder out = new StringBuilder();
- int i = 1;
- for (String line : code.split("\n")) {
- int start = out.length();
- out.append(i++);
- int numLength = out.length() - start;
- out.append(":");
- for (int spaces = 0; spaces < 7 - numLength; ++spaces){
- out.append(" ");
- }
- out.append(line);
- out.append('\n');
- }
- return out.toString();
- }
-
- public void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars) {
- this.debugSource = debugSource;
- this.debugLines = debugLines;
- this.debugVars = debugVars;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java
index de7ee96..8f1abcb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java
@@ -20,35 +20,59 @@ package org.apache.drill.exec.compile;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Arrays;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.drill.common.exceptions.ExpressionParsingException;
+import org.apache.drill.exec.compile.ClassTransformer.ClassNames;
import org.apache.drill.exec.exception.ClassTransformationException;
+import org.apache.drill.exec.server.options.OptionManager;
+import org.apache.drill.exec.server.options.OptionValidator;
+import org.apache.drill.exec.server.options.OptionValue;
+import org.apache.drill.exec.server.options.TypeValidators.LongValidator;
+import org.apache.drill.exec.server.options.TypeValidators.StringValidator;
import org.codehaus.commons.compiler.CompileException;
+import org.eigenbase.sql.SqlLiteral;
import com.google.common.collect.MapMaker;
public class QueryClassLoader extends URLClassLoader {
-
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(QueryClassLoader.class);
- private final ClassCompiler classCompiler;
+ public static final String JAVA_COMPILER_OPTION = "exec.java_compiler";
+ public static final StringValidator JAVA_COMPILER_VALIDATOR = new StringValidator(JAVA_COMPILER_OPTION, CompilerPolicy.DEFAULT.toString()) {
+ @Override
+ public OptionValue validate(SqlLiteral value) throws ExpressionParsingException {
+ OptionValue ov = super.validate(value);
+ try {
+ CompilerPolicy.valueOf(ov.string_val.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ throw new ExpressionParsingException(String.format("Invalid value '%s' specified for option '%s'. Valid values are %s.",
+ ov.string_val, getOptionName(), Arrays.toString(CompilerPolicy.values())));
+ }
+ return ov;
+ }
+ };
+
+ public static final String JAVA_COMPILER_JANINO_MAXSIZE_OPTION = "exec.java_compiler_janino_maxsize";
+ public static final OptionValidator JAVA_COMPILER_JANINO_MAXSIZE = new LongValidator(JAVA_COMPILER_JANINO_MAXSIZE_OPTION, 256*1024);
+
+ private ClassCompilerSelector compilerSelector;
+
private AtomicLong index = new AtomicLong(0);
+
private ConcurrentMap<String, byte[]> customClasses = new MapMaker().concurrencyLevel(4).makeMap();
- public QueryClassLoader(boolean useJanino) {
+ public QueryClassLoader(OptionManager sessionOptions) {
super(new URL[0]);
- if (useJanino) {
- this.classCompiler = new JaninoClassCompiler(this);
- } else {
- throw new UnsupportedOperationException("Drill no longer supports using the JDK class compiler.");
- }
+ compilerSelector = new ClassCompilerSelector(sessionOptions);
}
public long getNextClassIndex(){
return index.getAndIncrement();
}
-
+
public void injectByteCode(String className, byte[] classBytes) throws IOException {
if(customClasses.containsKey(className)) throw new IOException(String.format("The class defined {} has already been loaded.", className));
customClasses.put(className, classBytes);
@@ -64,10 +88,53 @@ public class QueryClassLoader extends URLClassLoader {
}
}
- public byte[][] getClassByteCode(final String className, final String sourcecode) throws CompileException, IOException,
- ClassNotFoundException, ClassTransformationException {
- byte[][] bc = classCompiler.getClassByteCode(className, sourcecode);
- return bc;
+ public byte[][] getClassByteCode(final ClassNames className, final String sourceCode)
+ throws CompileException, IOException, ClassNotFoundException, ClassTransformationException {
+ return compilerSelector.getClassByteCode(className, sourceCode);
+ }
+
+ public enum CompilerPolicy {
+ DEFAULT, JDK, JANINO;
+ }
+
+ private class ClassCompilerSelector {
+ private final CompilerPolicy policy;
+ private final long janinoThreshold;
+
+ private ClassCompiler jdkClassCompiler;
+ private ClassCompiler janinoClassCompiler;
+
+
+ ClassCompilerSelector(OptionManager sessionOptions) {
+ OptionValue value = sessionOptions.getOption(JAVA_COMPILER_OPTION);
+ this.policy = (value != null) ? CompilerPolicy.valueOf(value.string_val.toUpperCase()) : CompilerPolicy.DEFAULT;
+ value = sessionOptions.getOption(JAVA_COMPILER_JANINO_MAXSIZE_OPTION);
+ this.janinoThreshold = (value != null) ? value.num_val : JAVA_COMPILER_JANINO_MAXSIZE.getDefault().num_val;
+
+ this.janinoClassCompiler = new JaninoClassCompiler(QueryClassLoader.this);
+ this.jdkClassCompiler = new JDKClassCompiler(QueryClassLoader.this);
+ }
+
+ private byte[][] getClassByteCode(ClassNames className, String sourceCode)
+ throws CompileException, ClassNotFoundException, ClassTransformationException, IOException {
+ ClassCompiler classCompiler;
+ if (policy == CompilerPolicy.JDK || (policy == CompilerPolicy.DEFAULT && sourceCode.length() > janinoThreshold)) {
+ classCompiler = jdkClassCompiler;
+ } else {
+ classCompiler = janinoClassCompiler;
+ }
+
+ byte[][] bc = classCompiler.getClassByteCode(className, sourceCode);
+ /*
+ * final String baseDir = System.getProperty("java.io.tmpdir") + File.separator + classCompiler.getClass().getSimpleName();
+ * File classFile = new File(baseDir + className.clazz);
+ * classFile.getParentFile().mkdirs();
+ * BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(classFile));
+ * out.write(bc[0]);
+ * out.close();
+ */
+ return bc;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/02f1c82d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
index c80493c..4b79bba 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
@@ -17,904 +17,100 @@
*/
package org.apache.drill.exec.expr.fn;
-
-/*
- *
- * Modified so that we can avoid printing some things.
- *
- * Janino - An embedded Java[TM] compiler
- *
- * Copyright (c) 2001-2010, Arno Unkrig
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
- * following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
- * following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringReader;
import java.io.Writer;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.codehaus.janino.JaninoRuntimeException;
import org.codehaus.janino.Java;
-import org.codehaus.janino.Mod;
-import org.codehaus.janino.Parser;
-import org.codehaus.janino.Scanner;
-import org.codehaus.janino.Visitor.ComprehensiveVisitor;
+import org.codehaus.janino.UnparseVisitor;
import org.codehaus.janino.util.AutoIndentWriter;
/**
- * A visitor that unparses (un-compiles) an AST to a {@link Writer}. See
- * {@link #main(String[])} for a usage example.
+ * This is a modified version of {@link UnparseVisitor} so that we can avoid
+ * rendering few things. Based on janino version 2.7.4.
*/
-public class ModifiedUnparseVisitor implements ComprehensiveVisitor {
- protected final AutoIndentWriter aiw;
- protected final PrintWriter pw;
- private String returnLabel;
-
- /**
- * Testing of parsing/unparsing.
- * <p>
- * Reads compilation units from the files named on the command line
- * and unparses them to {@link System#out}.
- */
- public static void main(String[] args) throws Exception {
- Writer w = new BufferedWriter(new OutputStreamWriter(System.out));
- for (int i = 0; i < args.length; ++i) {
- String fileName = args[i];
-
- // Parse each compilation unit.
- FileReader r = new FileReader(fileName);
- Java.CompilationUnit cu;
- try {
- cu = new Parser(new Scanner(fileName, r)).parseCompilationUnit();
- } finally {
- r.close();
- }
-
- // Unparse each compilation unit.
- ModifiedUnparseVisitor.unparse(cu, w);
- }
- w.flush();
- }
-
- /**
- * Unparse the given {@link Java.CompilationUnit} to the given {@link Writer}.
- */
- public static void unparse(Java.CompilationUnit cu, Writer w) {
- ModifiedUnparseVisitor uv = new ModifiedUnparseVisitor(w);
- uv.unparseCompilationUnit(cu);
- uv.close();
- }
-
- public ModifiedUnparseVisitor(Writer w) {
- this.aiw = new AutoIndentWriter(w);
- this.pw = new PrintWriter(this.aiw, true);
- }
-
- /**
- * Flushes all generated code and closes the {@link Writer} that was passed
- * to {@link #ModifiedUnparseVisitor(Writer)}.
- */
- public void close() {
- this.pw.close();
- }
-
- public void unparseCompilationUnit(Java.CompilationUnit cu) {
- if (cu.optionalPackageDeclaration != null) {
- this.pw.println();
- this.pw.println("package " + cu.optionalPackageDeclaration.packageName + ';');
- }
- if (!cu.importDeclarations.isEmpty()) {
- this.pw.println();
- for (Iterator it = cu.importDeclarations.iterator(); it.hasNext();) {
- ((Java.CompilationUnit.ImportDeclaration) it.next()).accept(this);
- }
- }
- for (Iterator it = cu.packageMemberTypeDeclarations.iterator(); it.hasNext();) {
- this.pw.println();
- this.unparseTypeDeclaration((Java.PackageMemberTypeDeclaration) it.next());
- this.pw.println();
- }
- }
-
- public void visitSingleTypeImportDeclaration(Java.CompilationUnit.SingleTypeImportDeclaration stid) {
- this.pw.println("import " + Java.join(stid.identifiers, ".") + ';');
- }
- public void visitTypeImportOnDemandDeclaration(Java.CompilationUnit.TypeImportOnDemandDeclaration tiodd) {
- this.pw.println("import " + Java.join(tiodd.identifiers, ".") + ".*;");
- }
- public void visitSingleStaticImportDeclaration(Java.CompilationUnit.SingleStaticImportDeclaration ssid) {
- this.pw.println("import static " + Java.join(ssid.identifiers, ".") + ';');
- }
- public void visitStaticImportOnDemandDeclaration(Java.CompilationUnit.StaticImportOnDemandDeclaration siodd) {
- this.pw.println("import static " + Java.join(siodd.identifiers, ".") + ".*;");
- }
-
- public void visitLocalClassDeclaration(Java.LocalClassDeclaration lcd) {
- this.unparseNamedClassDeclaration(lcd);
- }
- public void visitMemberClassDeclaration(Java.MemberClassDeclaration mcd) {
- this.unparseNamedClassDeclaration(mcd);
- }
- public void visitMemberInterfaceDeclaration(Java.MemberInterfaceDeclaration mid) {
- this.unparseInterfaceDeclaration(mid);
- }
- public void visitPackageMemberClassDeclaration(Java.PackageMemberClassDeclaration pmcd) {
- this.unparseNamedClassDeclaration(pmcd);
- }
- public void visitPackageMemberInterfaceDeclaration(Java.PackageMemberInterfaceDeclaration pmid) {
- this.unparseInterfaceDeclaration(pmid);
- }
- public void visitConstructorDeclarator(Java.ConstructorDeclarator cd) {
- this.unparseDocComment(cd);
- this.unparseModifiers(cd.modifiers);
- Java.ClassDeclaration declaringClass = cd.getDeclaringClass();
- this.pw.print(
- declaringClass instanceof Java.NamedClassDeclaration
- ? ((Java.NamedClassDeclaration) declaringClass).name
- : "UNNAMED"
- );
- this.unparseFunctionDeclaratorRest(cd);
- this.pw.print(' ');
- if (cd.optionalConstructorInvocation != null) {
- this.pw.println('{');
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseBlockStatement(cd.optionalConstructorInvocation);
- this.pw.println(';');
-
- if (!cd.optionalStatements.isEmpty()) {
- this.pw.println();
- this.unparseStatements(cd.optionalStatements);
- }
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- } else
- if (cd.optionalStatements.isEmpty()) {
- this.pw.print("{}");
- } else
- {
- this.pw.println('{');
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseStatements(cd.optionalStatements);
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
- }
- public void visitMethodDeclarator(Java.MethodDeclarator md) {
- // modified to remove method declaration printing.
- if (md.optionalStatements == null) {
- this.pw.print(';');
- } else
- if (md.optionalStatements.isEmpty()) {
- this.pw.print(" {}");
- } else
- {
- this.pw.println(' ');
- // Add labels to handle return statements within function templates
- String[] fQCN = md.getDeclaringType().getClassName().split("\\.");
- returnLabel = fQCN[fQCN.length - 1] + "_" + md.name;
-
- this.pw.println(returnLabel + ": {");
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseStatements(md.optionalStatements);
- this.pw.print(AutoIndentWriter.UNINDENT);
- this.pw.println("}");
- this.pw.print(' ');
- }
-
- }
- public void visitFieldDeclaration(Java.FieldDeclaration fd) {
- this.unparseDocComment(fd);
- this.unparseModifiers(fd.modifiers);
- this.unparseType(fd.type);
- this.pw.print(' ');
- for (int i = 0; i < fd.variableDeclarators.length; ++i) {
- if (i > 0) this.pw.print(", ");
- this.unparseVariableDeclarator(fd.variableDeclarators[i]);
- }
- this.pw.print(';');
- }
- public void visitInitializer(Java.Initializer i) {
- if (i.statiC) this.pw.print("static ");
- this.unparseBlockStatement(i.block);
- }
- public void visitBlock(Java.Block b) {
- if (b.statements.isEmpty()) {
- this.pw.print("{}");
- return;
- }
- this.pw.println('{');
+public class ModifiedUnparseVisitor extends UnparseVisitor {
+
+ private String returnLabel;
+
+ /**
+ * Testing of parsing/unparsing.
+ * <p>
+ * Reads compilation units from the files named on the command line
+ * and unparses them to {@link System#out}.
+ */
+ public static void main(String[] args) throws Exception {
+ UnparseVisitor.main(args);
+ }
+
+ /**
+ * Unparse the given {@link Java.CompilationUnit} to the given {@link Writer}.
+ */
+ public static void unparse(Java.CompilationUnit cu, Writer w) {
+ UnparseVisitor.unparse(cu, w);
+ }
+
+ public ModifiedUnparseVisitor(Writer w) {
+ super(w);
+ }
+
+ public void visitMethodDeclarator(Java.MethodDeclarator md) {
+ if (md.optionalStatements == null) {
+ this.pw.print(';');
+ } else
+ if (md.optionalStatements.isEmpty()) {
+ this.pw.print(" {}");
+ } else {
+ this.pw.println(' ');
+ // Add labels to handle return statements within function templates
+ String[] fQCN = md.getDeclaringType().getClassName().split("\\.");
+ returnLabel = fQCN[fQCN.length - 1] + "_" + md.name;
+ this.pw.println(returnLabel + ": {");
this.pw.print(AutoIndentWriter.INDENT);
- this.unparseStatements(b.statements);
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
-
- private void unparseStatements(List statements) {
- int state = -1;
- for (Iterator it = statements.iterator(); it.hasNext();) {
- Java.BlockStatement bs = (Java.BlockStatement) it.next();
- int x = (
- bs instanceof Java.Block ? 1 :
- bs instanceof Java.LocalClassDeclarationStatement ? 2 :
- bs instanceof Java.LocalVariableDeclarationStatement ? 3 :
- bs instanceof Java.SynchronizedStatement ? 4 :
- 99
- );
- if (state != -1 && state != x) this.pw.println(AutoIndentWriter.CLEAR_TABULATORS);
- state = x;
-
- this.unparseBlockStatement(bs);
- this.pw.println();
- }
- }
- public void visitBreakStatement(Java.BreakStatement bs) {
- this.pw.print("break");
- if (bs.optionalLabel != null) this.pw.print(' ' + bs.optionalLabel);
- this.pw.print(';');
- }
- public void visitContinueStatement(Java.ContinueStatement cs) {
- this.pw.print("continue");
- if (cs.optionalLabel != null) this.pw.print(' ' + cs.optionalLabel);
- this.pw.print(';');
- }
- public void visitDoStatement(Java.DoStatement ds) {
- this.pw.print("do ");
- this.unparseBlockStatement(ds.body);
- this.pw.print("while (");
- this.unparse(ds.condition);
- this.pw.print(");");
- }
- public void visitEmptyStatement(Java.EmptyStatement es) {
- this.pw.print(';');
- }
- public void visitExpressionStatement(Java.ExpressionStatement es) {
- this.unparse(es.rvalue);
- this.pw.print(';');
- }
- public void visitForStatement(Java.ForStatement fs) {
- this.pw.print("for (");
- if (fs.optionalInit != null) {
- this.unparseBlockStatement(fs.optionalInit);
- } else {
- this.pw.print(';');
- }
- if (fs.optionalCondition != null) {
- this.pw.print(' ');
- this.unparse(fs.optionalCondition);
- }
- this.pw.print(';');
- if (fs.optionalUpdate != null) {
- this.pw.print(' ');
- for (int i = 0; i < fs.optionalUpdate.length; ++i) {
- if (i > 0) this.pw.print(", ");
- this.unparse(fs.optionalUpdate[i]);
- }
- }
- this.pw.print(") ");
- this.unparseBlockStatement(fs.body);
- }
- public void visitIfStatement(Java.IfStatement is) {
- this.pw.print("if (");
- this.unparse(is.condition);
- this.pw.print(") ");
- this.unparseBlockStatement(is.thenStatement);
- if (is.optionalElseStatement != null) {
- this.pw.println(" else");
- this.unparseBlockStatement(is.optionalElseStatement);
- }
- }
- public void visitLabeledStatement(Java.LabeledStatement ls) {
- this.pw.println(ls.label + ':');
- this.unparseBlockStatement(ls.body);
- }
- public void visitLocalClassDeclarationStatement(Java.LocalClassDeclarationStatement lcds) {
- this.unparseTypeDeclaration(lcds.lcd);
- }
- public void visitLocalVariableDeclarationStatement(Java.LocalVariableDeclarationStatement lvds) {
- this.unparseModifiers(lvds.modifiers);
- this.unparseType(lvds.type);
+ this.unparseStatements(md.optionalStatements);
+ this.pw.print(AutoIndentWriter.UNINDENT);
+ this.pw.println("}");
this.pw.print(' ');
- this.pw.print(AutoIndentWriter.TABULATOR);
- this.unparseVariableDeclarator(lvds.variableDeclarators[0]);
- for (int i = 1; i < lvds.variableDeclarators.length; ++i) {
- this.pw.print(", ");
- this.unparseVariableDeclarator(lvds.variableDeclarators[i]);
- }
- this.pw.print(';');
- }
- public void visitReturnStatement(Java.ReturnStatement rs) {
- this.pw.print("break " + returnLabel);
-
- if (rs.optionalReturnValue != null) {
- this.pw.print(' ');
- this.unparse(rs.optionalReturnValue);
- }
- this.pw.print(';');
- }
- public void visitSwitchStatement(Java.SwitchStatement ss) {
- this.pw.print("switch (");
- this.unparse(ss.condition);
- this.pw.println(") {");
- for (Iterator it = ss.sbsgs.iterator(); it.hasNext();) {
- Java.SwitchStatement.SwitchBlockStatementGroup sbgs = (
- (Java.SwitchStatement.SwitchBlockStatementGroup) it.next()
- );
- this.pw.print(AutoIndentWriter.UNINDENT);
- try {
- for (Iterator it2 = sbgs.caseLabels.iterator(); it2.hasNext();) {
- Java.Rvalue rv = (Java.Rvalue) it2.next();
- this.pw.print("case ");
- this.unparse(rv);
- this.pw.println(':');
- }
- if (sbgs.hasDefaultLabel) this.pw.println("default:");
- } finally {
- this.pw.print(AutoIndentWriter.INDENT);
- }
- for (Iterator it2 = sbgs.blockStatements.iterator(); it2.hasNext();) {
- this.unparseBlockStatement((Java.BlockStatement) it2.next());
- this.pw.println();
- }
- }
- this.pw.print('}');
- }
- public void visitSynchronizedStatement(Java.SynchronizedStatement ss) {
- this.pw.print("synchronized (");
- this.unparse(ss.expression);
- this.pw.print(") ");
- this.unparseBlockStatement(ss.body);
- }
- public void visitThrowStatement(Java.ThrowStatement ts) {
- this.pw.print("throw ");
- this.unparse(ts.expression);
- this.pw.print(';');
- }
- public void visitTryStatement(Java.TryStatement ts) {
- this.pw.print("try ");
- this.unparseBlockStatement(ts.body);
- for (Iterator it = ts.catchClauses.iterator(); it.hasNext();) {
- Java.CatchClause cc = (Java.CatchClause) it.next();
- this.pw.print(" catch (");
- this.unparseFormalParameter(cc.caughtException);
- this.pw.print(") ");
- this.unparseBlockStatement(cc.body);
- }
- if (ts.optionalFinally != null) {
- this.pw.print(" finally ");
- this.unparseBlockStatement(ts.optionalFinally);
- }
- }
- public void visitWhileStatement(Java.WhileStatement ws) {
- this.pw.print("while (");
- this.unparse(ws.condition);
- this.pw.print(") ");
- this.unparseBlockStatement(ws.body);
- }
- public void unparseVariableDeclarator(Java.VariableDeclarator vd) {
- this.pw.print(vd.name);
- for (int i = 0; i < vd.brackets; ++i) this.pw.print("[]");
- if (vd.optionalInitializer != null) {
- this.pw.print(" = ");
- this.unparseArrayInitializerOrRvalue(vd.optionalInitializer);
- }
- }
- public void unparseFormalParameter(Java.FunctionDeclarator.FormalParameter fp) {
- if (fp.finaL) this.pw.print("final ");
- this.unparseType(fp.type);
- this.pw.print(" " + AutoIndentWriter.TABULATOR + fp.name);
- }
- public void visitMethodInvocation(Java.MethodInvocation mi) {
- if (mi.optionalTarget != null) {
- this.unparseLhs(mi.optionalTarget, ".");
- this.pw.print('.');
- }
- this.pw.print(mi.methodName);
- this.unparseFunctionInvocationArguments(mi.arguments);
- }
- public void visitAlternateConstructorInvocation(Java.AlternateConstructorInvocation aci) {
- this.pw.print("this");
- this.unparseFunctionInvocationArguments(aci.arguments);
- }
- public void visitSuperConstructorInvocation(Java.SuperConstructorInvocation sci) {
- if (sci.optionalQualification != null) {
- this.unparseLhs(sci.optionalQualification, ".");
- this.pw.print('.');
- }
- this.pw.print("super");
- this.unparseFunctionInvocationArguments(sci.arguments);
- }
- public void visitNewClassInstance(Java.NewClassInstance nci) {
- if (nci.optionalQualification != null) {
- this.unparseLhs(nci.optionalQualification, ".");
- this.pw.print('.');
- }
- this.pw.print("new " + nci.type.toString());
- this.unparseFunctionInvocationArguments(nci.arguments);
- }
- public void visitAssignment(Java.Assignment a) {
- this.unparseLhs(a.lhs, a.operator);
- this.pw.print(' ' + a.operator + ' ');
- this.unparseRhs(a.rhs, a.operator);
- }
- public void visitAmbiguousName(Java.AmbiguousName an) { this.pw.print(an.toString()); }
- public void visitArrayAccessExpression(Java.ArrayAccessExpression aae) {
- this.unparseLhs(aae.lhs, "[ ]");
- this.pw.print('[');
- this.unparse(aae.index);
- this.pw.print(']');
- }
- public void visitArrayLength(Java.ArrayLength al) {
- this.unparseLhs(al.lhs, ".");
- this.pw.print(".length");
- }
- public void visitArrayType(Java.ArrayType at) {
- this.unparseType(at.componentType);
- this.pw.print("[]");
- }
- public void visitBasicType(Java.BasicType bt) {
- this.pw.print(bt.toString());
- }
- public void visitBinaryOperation(Java.BinaryOperation bo) {
- this.unparseLhs(bo.lhs, bo.op);
- this.pw.print(' ' + bo.op + ' ');
- this.unparseRhs(bo.rhs, bo.op);
- }
- public void visitCast(Java.Cast c) {
- this.pw.print('(');
- this.unparseType(c.targetType);
- this.pw.print(") ");
- this.unparseRhs(c.value, "cast");
- }
- public void visitClassLiteral(Java.ClassLiteral cl) {
- this.unparseType(cl.type);
- this.pw.print(".class");
- }
- public void visitConditionalExpression(Java.ConditionalExpression ce) {
- this.unparseLhs(ce.lhs, "?:");
- this.pw.print(" ? ");
- this.unparseLhs(ce.mhs, "?:");
- this.pw.print(" : ");
- this.unparseRhs(ce.rhs, "?:");
- }
- public void visitCrement(Java.Crement c) {
- if (c.pre) {
- this.pw.print(c.operator);
- this.unparseUnaryOperation(c.operand, c.operator + "x");
- } else
- {
- this.unparseUnaryOperation(c.operand, "x" + c.operator);
- this.pw.print(c.operator);
- }
- }
- public void visitFieldAccess(Java.FieldAccess fa) {
- this.unparseLhs(fa.lhs, ".");
- this.pw.print('.' + fa.field.getName());
- }
- public void visitFieldAccessExpression(Java.FieldAccessExpression fae) {
- this.unparseLhs(fae.lhs, ".");
- this.pw.print('.' + fae.fieldName);
- }
- public void visitSuperclassFieldAccessExpression(Java.SuperclassFieldAccessExpression scfae) {
- if (scfae.optionalQualification != null) {
- this.unparseType(scfae.optionalQualification);
- this.pw.print(".super." + scfae.fieldName);
- } else
- {
- this.pw.print("super." + scfae.fieldName);
- }
- }
- public void visitInstanceof(Java.Instanceof io) {
- this.unparseLhs(io.lhs, "instanceof");
- this.pw.print(" instanceof ");
- this.unparseType(io.rhs);
- }
- public void visitLiteral(Java.Literal l) { this.pw.print(l.toString()); }
- public void visitLocalVariableAccess(Java.LocalVariableAccess lva) { this.pw.print(lva.toString()); }
- public void visitNewArray(Java.NewArray na) {
- this.pw.print("new ");
- this.unparseType(na.type);
- for (int i = 0; i < na.dimExprs.length; ++i) {
- this.pw.print('[');
- this.unparse(na.dimExprs[i]);
- this.pw.print(']');
- }
- for (int i = 0; i < na.dims; ++i) {
- this.pw.print("[]");
- }
- }
- public void visitNewInitializedArray(Java.NewInitializedArray nai) {
- this.pw.print("new ");
- this.unparseType(nai.arrayType);
- this.pw.print(" ");
- this.unparseArrayInitializerOrRvalue(nai.arrayInitializer);
- }
- public void visitPackage(Java.Package p) { this.pw.print(p.toString()); }
- public void visitParameterAccess(Java.ParameterAccess pa) { this.pw.print(pa.toString()); }
- public void visitQualifiedThisReference(Java.QualifiedThisReference qtr) {
- this.unparseType(qtr.qualification);
- this.pw.print(".this");
- }
- public void visitReferenceType(Java.ReferenceType rt) { this.pw.print(rt.toString()); }
- public void visitRvalueMemberType(Java.RvalueMemberType rmt) { this.pw.print(rmt.toString()); }
- public void visitSimpleType(Java.SimpleType st) { this.pw.print(st.toString()); }
- public void visitSuperclassMethodInvocation(Java.SuperclassMethodInvocation smi) {
- this.pw.print("super." + smi.methodName);
- this.unparseFunctionInvocationArguments(smi.arguments);
- }
- public void visitThisReference(Java.ThisReference tr) {
- this.pw.print("this");
- }
- public void visitUnaryOperation(Java.UnaryOperation uo) {
- this.pw.print(uo.operator);
- this.unparseUnaryOperation(uo.operand, uo.operator + "x");
- }
- public void visitParenthesizedExpression(Java.ParenthesizedExpression pe) {
- this.pw.print('(');
- this.unparse(pe.value);
- this.pw.print(')');
- }
-
- // Helpers
-
- private void unparseBlockStatement(Java.BlockStatement blockStatement) {
- blockStatement.accept(this);
- }
-
- private void unparseTypeDeclaration(Java.TypeDeclaration typeDeclaration) {
- typeDeclaration.accept(this);
- }
-
- private void unparseType(Java.Type type) {
- ((Java.Atom) type).accept(this);
- }
-
- private void unparse(Java.Atom operand) {
- operand.accept(this);
- }
-
- /**
- * Iff the <code>operand</code> is unnatural for the <code>unaryOperator</code>, enclose the
- * <code>operand</code> in parentheses. Example: "a+b" is an unnatural operand for unary "!x".
- *
- * @param unaryOperator ++x --x +x -x ~x !x x++ x--
- */
- private void unparseUnaryOperation(Java.Rvalue operand, String unaryOperator) {
- int cmp = ModifiedUnparseVisitor.comparePrecedence(unaryOperator, operand);
- this.unparse(operand, cmp < 0);
- }
-
- /**
- * Iff the <code>lhs</code> is unnatural for the <code>binaryOperator</code>, enclose the
- * <code>lhs</code> in parentheses. Example: "a+b" is an unnatural lhs for operator "*".
- *
- * @param binaryOperator = +=... ?: || && | ^ & == != < > <= >= instanceof << >> >>> + - * / % cast
- */
-
- private void unparseLhs(Java.Atom lhs, String binaryOperator) {
- int cmp = ModifiedUnparseVisitor.comparePrecedence(binaryOperator, lhs);
- this.unparse(lhs, cmp < 0 || (cmp == 0 && ModifiedUnparseVisitor.isLeftAssociate(binaryOperator)));
- }
-
-
- /**
- * Iff the <code>rhs</code> is unnatural for the <code>binaryOperator</code>, enclose the
- * <code>rhs</code> in parentheses. Example: "a+b" is an unnatural rhs for operator "*".
- */
- private void unparseRhs(Java.Rvalue rhs, String binaryOperator) {
- int cmp = ModifiedUnparseVisitor.comparePrecedence(binaryOperator, rhs);
- this.unparse(rhs, cmp < 0 || (cmp == 0 && ModifiedUnparseVisitor.isRightAssociate(binaryOperator)));
- }
-
- private void unparse(Java.Atom operand, boolean natural) {
- if (!natural) this.pw.print("((( ");
- this.unparse(operand);
- if (!natural) this.pw.print(" )))");
- }
-
- /**
- * Return true iff operator is right associative e.g. <code>a = b = c</code> evaluates as
- * <code>a = (b = c)</code>.
- *
- * @return Return true iff operator is right associative
- */
- private static boolean isRightAssociate(String op) {
- return ModifiedUnparseVisitor.RIGHT_ASSOCIATIVE_OPERATORS.contains(op);
- }
-
- /**
- * Return true iff operator is left associative e.g. <code>a - b - c</code> evaluates as
- * <code>(a - b) - c</code>.
- *
- * @return Return true iff operator is left associative
- */
- private static boolean isLeftAssociate(String op) {
- return ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS.contains(op);
- }
-
- /**
- * Returns a value
- * <ul>
- * <li>< 0 iff the <code>operator</code> has lower precedence than the <code>operand</code>
- * <li>==; 0 iff the <code>operator</code> has equal precedence than the <code>operand</code>
- * <li>> 0 iff the <code>operator</code> has higher precedence than the <code>operand</code>
- * </ul>
- */
- private static int comparePrecedence(String operator, Java.Atom operand) {
- if (operand instanceof Java.BinaryOperation) {
- return (
- ModifiedUnparseVisitor.getOperatorPrecedence(operator)
- - ModifiedUnparseVisitor.getOperatorPrecedence(((Java.BinaryOperation) operand).op)
- );
- } else
- if (operand instanceof Java.UnaryOperation) {
- return (
- ModifiedUnparseVisitor.getOperatorPrecedence(operator)
- - ModifiedUnparseVisitor.getOperatorPrecedence(((Java.UnaryOperation) operand).operator + "x")
- );
- } else
- if (operand instanceof Java.ConditionalExpression) {
- return ModifiedUnparseVisitor.getOperatorPrecedence(operator) - ModifiedUnparseVisitor.getOperatorPrecedence("?:");
- } else
- if (operand instanceof Java.Instanceof) {
- return ModifiedUnparseVisitor.getOperatorPrecedence(operator) - ModifiedUnparseVisitor.getOperatorPrecedence("instanceof");
- } else
- if (operand instanceof Java.Cast) {
- return ModifiedUnparseVisitor.getOperatorPrecedence(operator) - ModifiedUnparseVisitor.getOperatorPrecedence("cast");
- } else
- if (operand instanceof Java.MethodInvocation || operand instanceof Java.FieldAccess) {
- return ModifiedUnparseVisitor.getOperatorPrecedence(operator) - ModifiedUnparseVisitor.getOperatorPrecedence(".");
- } else
- if (operand instanceof Java.NewArray) {
- return ModifiedUnparseVisitor.getOperatorPrecedence(operator) - ModifiedUnparseVisitor.getOperatorPrecedence("new");
- } else
- if (operand instanceof Java.Crement) {
- Java.Crement c = (Java.Crement) operand;
- return (
- ModifiedUnparseVisitor.getOperatorPrecedence(operator)
- - ModifiedUnparseVisitor.getOperatorPrecedence(c.pre ? c.operator + "x" : "x" + c.operator)
- );
- } else
- {
- // All other rvalues (e.g. literal) have higher precedence than any operator.
- return -1;
- }
- }
- private static int getOperatorPrecedence(String operator) {
- return ((Integer) ModifiedUnparseVisitor.OPERATOR_PRECEDENCE.get(operator)).intValue();
- }
- private static final Set LEFT_ASSOCIATIVE_OPERATORS = new HashSet();
- private static final Set RIGHT_ASSOCIATIVE_OPERATORS = new HashSet();
- private static final Set UNARY_OPERATORS = new HashSet();
- private static final Map OPERATOR_PRECEDENCE = new HashMap();
- static {
- Object[] ops = {
- ModifiedUnparseVisitor.RIGHT_ASSOCIATIVE_OPERATORS, "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=",
- "&=", "^=", "|=",
- ModifiedUnparseVisitor.RIGHT_ASSOCIATIVE_OPERATORS, "?:",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "||",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "&&",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "|",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "^",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "&",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "==", "!=",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "<", ">", "<=", ">=", "instanceof",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "<<", ">>", ">>>",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "+", "-",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "*", "/", "%",
- ModifiedUnparseVisitor.RIGHT_ASSOCIATIVE_OPERATORS, "cast",
- ModifiedUnparseVisitor.UNARY_OPERATORS, "++x", "--x", "+x", "-x", "~x", "!x",
- ModifiedUnparseVisitor.UNARY_OPERATORS, "x++", "x--",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, "new",
- ModifiedUnparseVisitor.LEFT_ASSOCIATIVE_OPERATORS, ".", "[ ]",
- };
- int precedence = 0;
- LOOP1: for (int i = 0;;) {
- Set s = (Set) ops[i++];
- Integer pi = new Integer(++precedence);
- for (;;) {
- if (i == ops.length) break LOOP1;
- if (!(ops[i] instanceof String)) break;
- String op = (String) ops[i++];
- s.add(op);
- ModifiedUnparseVisitor.OPERATOR_PRECEDENCE.put(op, pi);
- }
- }
- }
-
- private void unparseNamedClassDeclaration(Java.NamedClassDeclaration ncd) {
- this.unparseDocComment(ncd);
- this.unparseModifiers(ncd.getModifiers());
- this.pw.print("class " + ncd.name);
- if (ncd.optionalExtendedType != null) {
- this.pw.print(" extends ");
- this.unparseType(ncd.optionalExtendedType);
- }
- if (ncd.implementedTypes.length > 0) this.pw.print(" implements " + Java.join(ncd.implementedTypes, ", "));
- this.pw.println(" {");
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseClassDeclarationBody(ncd);
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
- private void unparseArrayInitializerOrRvalue(Java.ArrayInitializerOrRvalue aiorv) {
- if (aiorv instanceof Java.Rvalue) {
- this.unparse((Java.Rvalue) aiorv);
- } else
- if (aiorv instanceof Java.ArrayInitializer) {
- Java.ArrayInitializer ai = (Java.ArrayInitializer) aiorv;
- if (ai.values.length == 0) {
- this.pw.print("{}");
- } else
- {
- this.pw.print("{ ");
- this.unparseArrayInitializerOrRvalue(ai.values[0]);
- for (int i = 1; i < ai.values.length; ++i) {
- this.pw.print(", ");
- this.unparseArrayInitializerOrRvalue(ai.values[i]);
- }
- this.pw.print(" }");
- }
- } else
- {
- throw new JaninoRuntimeException(
- "Unexpected array initializer or rvalue class "
- + aiorv.getClass().getName()
- );
- }
- }
-
- public void visitAnonymousClassDeclaration(Java.AnonymousClassDeclaration acd) {
- this.unparseType(acd.baseType);
- this.pw.println(" {");
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseClassDeclarationBody(acd);
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
- public void visitNewAnonymousClassInstance(Java.NewAnonymousClassInstance naci) {
- if (naci.optionalQualification != null) {
- this.unparseLhs(naci.optionalQualification, ".");
- this.pw.print('.');
- }
- this.pw.print("new " + naci.anonymousClassDeclaration.baseType.toString() + '(');
- for (int i = 0; i < naci.arguments.length; ++i) {
- if (i > 0) this.pw.print(", ");
- this.unparse(naci.arguments[i]);
- }
- this.pw.println(") {");
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseClassDeclarationBody(naci.anonymousClassDeclaration);
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
- // Multi-line!
- private void unparseClassDeclarationBody(Java.ClassDeclaration cd) {
- for (Iterator it = cd.constructors.iterator(); it.hasNext();) {
- this.pw.println();
- ((Java.ConstructorDeclarator) it.next()).accept(this);
- this.pw.println();
- }
- this.unparseAbstractTypeDeclarationBody(cd);
- for (Iterator it = cd.variableDeclaratorsAndInitializers.iterator(); it.hasNext();) {
- this.pw.println();
- ((Java.TypeBodyDeclaration) it.next()).accept(this);
- this.pw.println();
- }
- }
- private void unparseInterfaceDeclaration(Java.InterfaceDeclaration id) {
- this.unparseDocComment(id);
- this.unparseModifiers(id.getModifiers());
- //make sure we print "interface", even if it wasn't in the modifiers
- if ((id.getModifiers() & Mod.INTERFACE) == 0) {
- this.pw.print("interface ");
- }
- this.pw.print(id.name);
- if (id.extendedTypes.length > 0) this.pw.print(" extends " + Java.join(id.extendedTypes, ", "));
- this.pw.println(" {");
- this.pw.print(AutoIndentWriter.INDENT);
- this.unparseAbstractTypeDeclarationBody(id);
- for (Iterator it = id.constantDeclarations.iterator(); it.hasNext();) {
- ((Java.TypeBodyDeclaration) it.next()).accept(this);
- this.pw.println();
- }
- this.pw.print(AutoIndentWriter.UNINDENT + "}");
- }
- // Multi-line!
- private void unparseAbstractTypeDeclarationBody(Java.AbstractTypeDeclaration atd) {
- for (Iterator it = atd.getMethodDeclarations().iterator(); it.hasNext();) {
- this.pw.println();
- ((Java.MethodDeclarator) it.next()).accept(this);
- this.pw.println();
- }
- for (Iterator it = atd.getMemberTypeDeclarations().iterator(); it.hasNext();) {
- this.pw.println();
- ((Java.TypeBodyDeclaration) it.next()).accept(this);
- this.pw.println();
- }
- }
- private void unparseFunctionDeclaratorRest(Java.FunctionDeclarator fd) {
- boolean big = fd.formalParameters.length >= 4;
- this.pw.print('(');
- if (big) { this.pw.println(); this.pw.print(AutoIndentWriter.INDENT); }
- for (int i = 0; i < fd.formalParameters.length; ++i) {
- if (i > 0) {
- if (big) {
- this.pw.println(',');
- } else
- {
- this.pw.print(", ");
- }
- }
- this.unparseFormalParameter(fd.formalParameters[i]);
- }
- if (big) { this.pw.println(); this.pw.print(AutoIndentWriter.UNINDENT); }
- this.pw.print(')');
- if (fd.thrownExceptions.length > 0) this.pw.print(" throws " + Java.join(fd.thrownExceptions, ", "));
- }
- private void unparseDocComment(Java.DocCommentable dc) {
- String optionalDocComment = dc.getDocComment();
- if (optionalDocComment != null) {
- this.pw.print("/**");
- BufferedReader br = new BufferedReader(new StringReader(optionalDocComment));
- for (;;) {
- String line;
- try {
- line = br.readLine();
- } catch (IOException e) {
- throw new JaninoRuntimeException();
- }
- if (line == null) break;
- this.pw.println(line);
- this.pw.print(" *");
- }
- this.pw.println("/");
- }
- }
- private void unparseModifiers(short modifiers) {
- if (modifiers != 0) {
- this.pw.print(Mod.shortToString(modifiers) + ' ');
- }
- }
- private void unparseFunctionInvocationArguments(Java.Rvalue[] arguments) {
- boolean big = arguments.length >= 5;
- this.pw.print('(');
- if (big) { this.pw.println(); this.pw.print(AutoIndentWriter.INDENT); }
- for (int i = 0; i < arguments.length; ++i) {
- if (i > 0) {
- if (big) {
- this.pw.println(',');
- } else
- {
- this.pw.print(", ");
- }
- }
- this.unparse(arguments[i]);
- }
- if (big) { this.pw.println(); this.pw.print(AutoIndentWriter.UNINDENT); }
- this.pw.print(')');
- }
-
+ }
+ }
+
+ public void visitReturnStatement(Java.ReturnStatement rs) {
+ this.pw.print("break " + returnLabel);
+ if (rs.optionalReturnValue != null) {
+ this.pw.print(' ');
+ this.unparse(rs.optionalReturnValue);
+ }
+ this.pw.print(';');
+ }
+
+ /*
+ * The following helper methods are copied from the parent class since they
+ * are declared private in the parent class and can not be used in the child
+ * class (this).
+ */
+
+ private void unparseStatements(List<? extends Java.BlockStatement> statements) {
+ int state = -1;
+ for (Java.BlockStatement bs : statements) {
+ int x = (
+ bs instanceof Java.Block ? 1 :
+ bs instanceof Java.LocalClassDeclarationStatement ? 2 :
+ bs instanceof Java.LocalVariableDeclarationStatement ? 3 :
+ bs instanceof Java.SynchronizedStatement ? 4 :
+ 99
+ );
+ if (state != -1 && state != x) this.pw.println(AutoIndentWriter.CLEAR_TABULATORS);
+ state = x;
+
+ this.unparseBlockStatement(bs);
+ this.pw.println();
+ }
+ }
+
+ private void unparseBlockStatement(Java.BlockStatement blockStatement) {
+ blockStatement.accept(this);
+ }
+
+ private void unparse(Java.Atom operand) {
+ operand.accept(this);
+ }
}
[02/17] git commit: DRILL-988: trunc(num) bugfix handle data loss
Posted by ja...@apache.org.
DRILL-988: trunc(num) bugfix handle data loss
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/785aa5a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/785aa5a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/785aa5a2
Branch: refs/heads/master
Commit: 785aa5a254254e782d13fba562ec47ec0be7676d
Parents: 699851b
Author: Yash Sharma <ya...@snapdeal.com>
Authored: Thu May 29 00:29:11 2014 +0530
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:26:35 2014 -0700
----------------------------------------------------------------------
exec/java-exec/src/main/codegen/data/MathFunc.tdd | 4 ++--
exec/java-exec/src/main/codegen/templates/MathFunctions.java | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/785aa5a2/exec/java-exec/src/main/codegen/data/MathFunc.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/MathFunc.tdd b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
index b5b5543..cdce365 100644
--- a/exec/java-exec/src/main/codegen/data/MathFunc.tdd
+++ b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
@@ -82,7 +82,7 @@ unaryMathFunctions : [
{input: "UInt8", outputType: "UInt8", castType: "long"}
]
},
- {className: "Trunc", funcName: "trunc", javaFunc : "(long)", types: [
+ {className: "Trunc", funcName: "trunc", types: [
{input: "Int", outputType: "Int", castType: "int"},
{input: "BigInt", outputType: "BigInt", castType: "long"},
{input: "Float4", outputType: "Float4", castType: "float"},
@@ -90,7 +90,7 @@ unaryMathFunctions : [
{input: "SmallInt", outputType: "SmallInt", castType: "short"},
{input: "TinyInt", outputType: "TinyInt", castType: "byte"},
{input: "UInt1", outputType: "UInt1", castType: "byte"},
- {input: "UInt2", outputType: "UInt2", castType: "char"},
+ {input: "UInt2", outputType: "UInt2", castType: "int", extraCast: "char"},
{input: "UInt4", outputType: "UInt4", castType: "int"},
{input: "UInt8", outputType: "UInt8", castType: "long"}
]
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/785aa5a2/exec/java-exec/src/main/codegen/templates/MathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/MathFunctions.java b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
index c4298fb..8986b8a 100644
--- a/exec/java-exec/src/main/codegen/templates/MathFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
@@ -67,7 +67,13 @@ public class GMathFunctions{
}
public void eval() {
+
+ <#if func.funcName=='trunc'>
+ java.math.BigDecimal bd = new java.math.BigDecimal(String.valueOf(in.value)).setScale(0, java.math.BigDecimal.ROUND_DOWN);
+ out.value = <#if type.extraCast ??>(${type.extraCast})</#if>bd.${type.castType}Value();
+ <#else>
out.value =(${type.castType}) ${func.javaFunc}(in.value);
+ </#if>
}
}
[07/17] git commit: DRILL-1123: Use double type for decimal division
Posted by ja...@apache.org.
DRILL-1123: Use double type for decimal division
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/c4a82f5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/c4a82f5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/c4a82f5e
Branch: refs/heads/master
Commit: c4a82f5ee4f461e85e82c9d8af01756340526db9
Parents: a6e296c
Author: Mehant Baid <me...@gmail.com>
Authored: Fri Jul 11 15:31:37 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sun Jul 20 16:29:47 2014 -0700
----------------------------------------------------------------------
.../src/main/codegen/templates/Decimal/DecimalFunctions.java | 4 ++--
.../test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c4a82f5e/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
index 03e9a24..671d15b 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
@@ -505,7 +505,7 @@ public class ${type.name}Functions {
}
}
- @FunctionTemplate(name = "divide", scope = FunctionTemplate.FunctionScope.DECIMAL_DIV_SCALE, nulls = NullHandling.NULL_IF_NULL)
+ @FunctionTemplate(name = "exact_divide", scope = FunctionTemplate.FunctionScope.DECIMAL_DIV_SCALE, nulls = NullHandling.NULL_IF_NULL)
public static class ${type.name}DivideFunction implements DrillSimpleFunc {
@Param ${type.name}Holder left;
@@ -1304,7 +1304,7 @@ public class ${type.name}Functions {
}
}
- @FunctionTemplate(name = "divide", scope = FunctionTemplate.FunctionScope.DECIMAL_DIV_SCALE, nulls = NullHandling.NULL_IF_NULL)
+ @FunctionTemplate(name = "exact_divide", scope = FunctionTemplate.FunctionScope.DECIMAL_DIV_SCALE, nulls = NullHandling.NULL_IF_NULL)
public static class ${type.name}DivideFunction implements DrillSimpleFunc {
@Param ${type.name}Holder left;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/c4a82f5e/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
index 3a8bcbc..4651b1e 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
@@ -607,6 +607,7 @@ public class TestFunctionsQuery {
"DECIMAL_DOUBLE_CAST=1.0001\n");
}
+ @Ignore("we don't have decimal division")
@Test
public void testCastDecimalDivide() throws Exception {
String query = "select (cast('9' as decimal(9, 1)) / cast('2' as decimal(4, 1))) as DEC9_DIV, " +