s/bin_substr/byte_substr

Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/31f19649
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/31f19649
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/31f19649

Branch: refs/heads/master
Commit: 31f196497e7e0d1bd6cdc852ff3e9f16dd8c5072
Parents: 71e8ffe
Author: Ben Becker <[email protected]>
Authored: Sun Aug 4 00:35:33 2013 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Mon Aug 5 16:44:58 2013 -0700

----------------------------------------------------------------------
 .../drill/exec/expr/fn/impl/BinSubstring.java   | 104 -------------------
 .../drill/exec/expr/fn/impl/ByteSubstring.java  | 103 ++++++++++++++++++
 .../exec/physical/impl/TestSimpleFunctions.java |   4 +-
 .../resources/functions/testByteSubstring.json  |  37 +++++++
 .../functions/testSubstringBinary.json          |  37 -------
 5 files changed, 142 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/31f19649/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BinSubstring.java
----------------------------------------------------------------------
diff --git 
a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BinSubstring.java
 
b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BinSubstring.java
deleted file mode 100644
index e608a34..0000000
--- 
a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BinSubstring.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- 
******************************************************************************/
-
-package org.apache.drill.exec.expr.fn.impl;
-
-import org.apache.drill.common.expression.*;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.Output;
-import org.apache.drill.exec.expr.annotations.Param;
-import org.apache.drill.exec.record.RecordBatch;
-import org.apache.drill.exec.vector.*;
-
-// TODO: implement optional length parameter
-
-/**
- * Evaluate a substring expression for a given value; specifying the start
- * position, and optionally the end position.
- *
- *  - If the start position is negative, start from abs(start) characters from
- *    the end of the buffer.
- *
- *  - If no length is specified, continue to the end of the string.
- *
- *  - If the substring expression's length exceeds the value's upward bound, 
the
- *    value's length will be used.
- *
- *  - If the substring is invalid, return an empty string.
- */
-@FunctionTemplate(name = "binsubstring",
-                  scope = FunctionTemplate.FunctionScope.SIMPLE,
-                  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
-public class BinSubstring implements DrillFunc {
-
-  @Param VarBinaryHolder string;
-  @Param BigIntHolder offset;
-  @Param BigIntHolder length;
-  @Output VarBinaryHolder out;
-
-  @Override
-  public void setup(RecordBatch incoming) { }
-
-  @Override
-  public void eval() {
-    out.buffer = string.buffer;
-
-    // handle invalid values; e.g. SUBSTRING(value, 0, x) or SUBSTRING(value, 
x, 0)
-    if (offset.value == 0 || length.value <= 0) {
-
-      out.start = 0;
-      out.end = 0;
-
-    } else {
-
-      // handle negative and positive offset values
-      if (offset.value < 0)
-        out.start = string.end + (int)offset.value;
-      else
-        out.start = (int)offset.value - 1;
-  
-      // calculate end position from length and truncate to upper value bounds
-      if (out.start + length.value > string.end)
-        out.end = string.end;
-      else
-        out.end = out.start + (int)length.value;
-
-    }
-  }
-
-  public static class Provider implements CallProvider {
-
-    @Override
-    public FunctionDefinition[] getFunctionDefintions() {
-      return new FunctionDefinition[] {
-          FunctionDefinition.simple("binsubstring",
-                                    new BasicArgumentValidator(new 
Arg(Types.required(TypeProtos.MinorType.VARBINARY),
-                                                                       
Types.optional(TypeProtos.MinorType.VARBINARY)),
-                                                               new Arg(false, 
false, "offset", TypeProtos.MinorType.BIGINT),
-                                                               new Arg(false, 
false, "length", TypeProtos.MinorType.BIGINT)),
-                                    new 
OutputTypeDeterminer.SameAsFirstInput(),
-                                    "bin_substring",
-                                    "bin_substr")
-      };
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/31f19649/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
----------------------------------------------------------------------
diff --git 
a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
 
b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
new file mode 100644
index 0000000..3cc22a9
--- /dev/null
+++ 
b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
******************************************************************************/
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import org.apache.drill.common.expression.*;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.vector.*;
+
+// TODO: implement optional length parameter
+
+/**
+ * Evaluate a substring expression for a given value; specifying the start
+ * position, and optionally the end position.
+ *
+ *  - If the start position is negative, start from abs(start) characters from
+ *    the end of the buffer.
+ *
+ *  - If no length is specified, continue to the end of the string.
+ *
+ *  - If the substring expression's length exceeds the value's upward bound, 
the
+ *    value's length will be used.
+ *
+ *  - If the substring is invalid, return an empty string.
+ */
+@FunctionTemplate(name = "bytesubstring",
+                  scope = FunctionTemplate.FunctionScope.SIMPLE,
+                  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+public class ByteSubstring implements DrillFunc {
+
+  @Param VarBinaryHolder string;
+  @Param BigIntHolder offset;
+  @Param BigIntHolder length;
+  @Output VarBinaryHolder out;
+
+  @Override
+  public void setup(RecordBatch incoming) { }
+
+  @Override
+  public void eval() {
+    out.buffer = string.buffer;
+
+    // handle invalid values; e.g. SUBSTRING(value, 0, x) or SUBSTRING(value, 
x, 0)
+    if (offset.value == 0 || length.value <= 0) {
+
+      out.start = 0;
+      out.end = 0;
+
+    } else {
+
+      // handle negative and positive offset values
+      if (offset.value < 0)
+        out.start = string.end + (int)offset.value;
+      else
+        out.start = (int)offset.value - 1;
+  
+      // calculate end position from length and truncate to upper value bounds
+      if (out.start + length.value > string.end)
+        out.end = string.end;
+      else
+        out.end = out.start + (int)length.value;
+
+    }
+  }
+
+  public static class Provider implements CallProvider {
+
+    @Override
+    public FunctionDefinition[] getFunctionDefintions() {
+      return new FunctionDefinition[] {
+          FunctionDefinition.simple("bytesubstring",
+                                    new BasicArgumentValidator(new 
Arg(Types.required(TypeProtos.MinorType.VARBINARY),
+                                                                       
Types.optional(TypeProtos.MinorType.VARBINARY)),
+                                                               new Arg(false, 
false, "offset", TypeProtos.MinorType.BIGINT),
+                                                               new Arg(false, 
false, "length", TypeProtos.MinorType.BIGINT)),
+                                    new 
OutputTypeDeterminer.SameAsFirstInput(),
+                                    "byte_substr")
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/31f19649/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
----------------------------------------------------------------------
diff --git 
a/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
 
b/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
index 4211db1..ce5dccd 100644
--- 
a/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
+++ 
b/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java
@@ -185,7 +185,7 @@ public class TestSimpleFunctions {
   }
 
   @Test
-  public void testSubstringBinary(@Injectable final DrillbitContext bitContext,
+  public void testByteSubstring(@Injectable final DrillbitContext bitContext,
                                   @Injectable UserServer.UserClientConnection 
connection) throws Throwable{
 
     new NonStrictExpectations(){{
@@ -194,7 +194,7 @@ public class TestSimpleFunctions {
     }};
 
     PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), 
CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
-    PhysicalPlan plan = 
reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/testSubstringBinary.json"),
 Charsets.UTF_8));
+    PhysicalPlan plan = 
reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/testByteSubstring.json"),
 Charsets.UTF_8));
     FunctionImplementationRegistry registry = new 
FunctionImplementationRegistry(c);
     FragmentContext context = new FragmentContext(bitContext, 
ExecProtos.FragmentHandle.getDefaultInstance(), connection, null, registry);
     SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, 
(FragmentRoot) plan.getSortedOperators(false).iterator().next()));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/31f19649/sandbox/prototype/exec/java-exec/src/test/resources/functions/testByteSubstring.json
----------------------------------------------------------------------
diff --git 
a/sandbox/prototype/exec/java-exec/src/test/resources/functions/testByteSubstring.json
 
b/sandbox/prototype/exec/java-exec/src/test/resources/functions/testByteSubstring.json
new file mode 100644
index 0000000..3c246c5
--- /dev/null
+++ 
b/sandbox/prototype/exec/java-exec/src/test/resources/functions/testByteSubstring.json
@@ -0,0 +1,37 @@
+{
+    head:{
+        type:"APACHE_DRILL_PHYSICAL",
+        version:"1",
+        generator:{
+            type:"manual"
+        }
+    },
+    graph:[
+        {
+            @id:1,
+            pop:"mock-scan",
+            url: "http://apache.org";,
+            entries:[
+               {records: 100, types: [
+                 {name: "blue", type: "INT", mode: "REQUIRED"},
+                 {name: "red", type: "BIGINT", mode: "REQUIRED"},
+                 {name: "yellow", type: "VARBINARY", mode: "OPTIONAL"},
+                 {name: "green", type: "INT", mode: "REQUIRED"}
+               ]}
+            ]
+        },
+        {
+            @id:2,
+            child: 1,
+            pop:"project",
+            exprs: [
+              { ref: "col3", expr:"byte_substr(yellow, -3, 2)" }
+            ]
+        },
+        {
+            @id: 3,
+            child: 2,
+            pop: "screen"
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/31f19649/sandbox/prototype/exec/java-exec/src/test/resources/functions/testSubstringBinary.json
----------------------------------------------------------------------
diff --git 
a/sandbox/prototype/exec/java-exec/src/test/resources/functions/testSubstringBinary.json
 
b/sandbox/prototype/exec/java-exec/src/test/resources/functions/testSubstringBinary.json
deleted file mode 100644
index f68c179..0000000
--- 
a/sandbox/prototype/exec/java-exec/src/test/resources/functions/testSubstringBinary.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
-    head:{
-        type:"APACHE_DRILL_PHYSICAL",
-        version:"1",
-        generator:{
-            type:"manual"
-        }
-    },
-    graph:[
-        {
-            @id:1,
-            pop:"mock-scan",
-            url: "http://apache.org";,
-            entries:[
-               {records: 100, types: [
-                 {name: "blue", type: "INT", mode: "REQUIRED"},
-                 {name: "red", type: "BIGINT", mode: "REQUIRED"},
-                 {name: "yellow", type: "VARBINARY", mode: "OPTIONAL"},
-                 {name: "green", type: "INT", mode: "REQUIRED"}
-               ]}
-            ]
-        },
-        {
-            @id:2,
-            child: 1,
-            pop:"project",
-            exprs: [
-              { ref: "col3", expr:"bin_substring(yellow, -3, 2)" }
-            ]
-        },
-        {
-            @id: 3,
-            child: 2,
-            pop: "screen"
-        }
-    ]
-}
\ No newline at end of file

Reply via email to