Repository: incubator-drill
Updated Branches:
  refs/heads/master 337e9f65e -> 6bb121621
Updated Tags:  refs/tags/0.6.0-incubating [created] 3daef7f55


DRILL-1541: Add big endian version of convert to/from for double and float


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

Branch: refs/heads/master
Commit: 6bb12162173c0a86a5c48372ae49e484174e8bfa
Parents: 337e9f6
Author: Steven Phillips <[email protected]>
Authored: Wed Oct 15 17:01:39 2014 -0700
Committer: Steven Phillips <[email protected]>
Committed: Fri Oct 17 13:02:11 2014 -0700

----------------------------------------------------------------------
 .../expr/fn/impl/conv/DoubleBEConvertFrom.java  | 47 +++++++++++++++++
 .../expr/fn/impl/conv/DoubleBEConvertTo.java    | 55 ++++++++++++++++++++
 .../expr/fn/impl/conv/FloatBEConvertFrom.java   | 47 +++++++++++++++++
 .../expr/fn/impl/conv/FloatBEConvertTo.java     | 55 ++++++++++++++++++++
 .../physical/impl/TestConvertFunctions.java     | 11 ++++
 5 files changed, 215 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/6bb12162/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertFrom.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertFrom.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertFrom.java
new file mode 100644
index 0000000..011c7a6
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * 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.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+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.Float8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromDOUBLE_BE", scope = 
FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+public class DoubleBEConvertFrom implements DrillSimpleFunc {
+
+  @Param VarBinaryHolder in;
+  @Output Float8Holder out;
+
+  @Override
+  public void setup(RecordBatch incoming) { }
+
+  @Override
+  public void eval() {
+    org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, 
in.start, in.end, 8);
+
+    in.buffer.readerIndex(in.start);
+    out.value = 
Double.longBitsToDouble(Long.reverseBytes(in.buffer.readLong()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/6bb12162/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertTo.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertTo.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertTo.java
new file mode 100644
index 0000000..948f8b0
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/DoubleBEConvertTo.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+
+ * 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.conv;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+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.Float8Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+import javax.inject.Inject;
+
+@FunctionTemplate(name = "convert_toDOUBLE_BE", scope = FunctionScope.SIMPLE, 
nulls = NullHandling.NULL_IF_NULL)
+public class DoubleBEConvertTo implements DrillSimpleFunc {
+
+  @Param Float8Holder in;
+  @Output VarBinaryHolder out;
+  @Inject DrillBuf buffer;
+
+
+  @Override
+  public void setup(RecordBatch incoming) {
+    buffer = buffer.reallocIfNeeded(8);
+  }
+
+  @Override
+  public void eval() {
+    buffer.clear();
+    buffer.writeLong(Long.reverseBytes(Double.doubleToLongBits(in.value)));
+    out.buffer = buffer;
+    out.start = 0;
+    out.end = 8;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/6bb12162/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertFrom.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertFrom.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertFrom.java
new file mode 100644
index 0000000..095588c
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertFrom.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+
+ * 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.conv;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+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.Float4Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@FunctionTemplate(name = "convert_fromFLOAT_BE", scope = FunctionScope.SIMPLE, 
nulls = NullHandling.NULL_IF_NULL)
+public class FloatBEConvertFrom implements DrillSimpleFunc {
+
+  @Param VarBinaryHolder in;
+  @Output Float4Holder out;
+
+  @Override
+  public void setup(RecordBatch incoming) { }
+
+  @Override
+  public void eval() {
+    org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, 
in.start, in.end, 4);
+
+    in.buffer.readerIndex(in.start);
+    out.value = 
Float.intBitsToFloat(Integer.reverseBytes(in.buffer.readInt()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/6bb12162/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertTo.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertTo.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertTo.java
new file mode 100644
index 0000000..4b6d51d
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/conv/FloatBEConvertTo.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+
+ * 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.conv;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+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.Float4Holder;
+import org.apache.drill.exec.expr.holders.VarBinaryHolder;
+import org.apache.drill.exec.record.RecordBatch;
+
+import javax.inject.Inject;
+
+@FunctionTemplate(name = "convert_toFLOAT_BE", scope = FunctionScope.SIMPLE, 
nulls = NullHandling.NULL_IF_NULL)
+public class FloatBEConvertTo implements DrillSimpleFunc {
+
+  @Param Float4Holder in;
+  @Output VarBinaryHolder out;
+  @Inject DrillBuf buffer;
+
+
+  @Override
+  public void setup(RecordBatch incoming) {
+    buffer = buffer.reallocIfNeeded(4);
+  }
+
+  @Override
+  public void eval() {
+    buffer.clear();
+    buffer.writeInt(Integer.reverseBytes(Float.floatToIntBits(in.value)));
+    out.buffer = buffer;
+    out.start = 0;
+    out.end = 4;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/6bb12162/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 2c03b69..a6cce3c 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
@@ -268,6 +268,11 @@ public class TestConvertFunctions extends BaseTestQuery {
   }
 
   @Test
+  public void testFloats2be() throws Throwable {
+    verifyPhysicalPlan("convert_from(convert_to(cast(77 as float4), 
'FLOAT_BE'), 'FLOAT_BE')", new Float(77.0));
+  }
+
+  @Test
   public void testFloats3() throws Throwable {
     verifyPhysicalPlan("convert_to(cast(1.4e-45 as float4), 'FLOAT')", new 
byte[] {1, 0, 0, 0});
   }
@@ -284,6 +289,12 @@ public class TestConvertFunctions extends BaseTestQuery {
   }
 
   @Test
+  public void testFloats5be(@Injectable final DrillbitContext bitContext,
+                          @Injectable UserServer.UserClientConnection 
connection) throws Throwable {
+    verifyPhysicalPlan("convert_from(convert_to(cast(77 as float8), 
'DOUBLE_BE'), 'DOUBLE_BE')", 77.0);
+  }
+
+  @Test
   public void testFloats6(@Injectable final DrillbitContext bitContext,
                            @Injectable UserServer.UserClientConnection 
connection) throws Throwable {
     verifyPhysicalPlan("convert_to(cast(77 as float8), 'DOUBLE')", new byte[] 
{0, 0, 0, 0, 0, 64, 83, 64});

Reply via email to