drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject [4/4] drill git commit: DRILL-5424: Fix IOBE for reverse function
Date Mon, 17 Apr 2017 05:24:09 GMT
DRILL-5424: Fix IOBE for reverse function

close apache/drill#815


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

Branch: refs/heads/master
Commit: 72903d01424139057d4309ce6655e0aecee2573e
Parents: 3b71cbd
Author: Volodymyr Vysotskyi <vvovyk@gmail.com>
Authored: Mon Apr 10 13:16:52 2017 +0000
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Sun Apr 16 22:20:31 2017 -0700

----------------------------------------------------------------------
 .../exec/expr/fn/impl/StringFunctions.java      | 20 +++++------
 .../exec/expr/fn/impl/TestStringFunctions.java  | 37 +++++++++++++++++++-
 2 files changed, 46 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/72903d01/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 8196728..d90581e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -1698,20 +1698,20 @@ public class StringFunctions{
       out.start = 0;
       out.end = len;
       out.buffer = buffer = buffer.reallocIfNeeded(len);
-      int charlen = 0;
+      int charLen;
 
-      int index = in.end;
-      int innerindex = 0;
+      int index = out.end;
+      int innerIndex;
 
-      for (int id = in.start; id < in.end; id += charlen) {
-        innerindex = charlen = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(in.buffer,
id);
+      for (int id = in.start; id < in.end; id += charLen) {
+        innerIndex = charLen = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(in.buffer,
id);
 
-        while (innerindex > 0) {
-          out.buffer.setByte(index - innerindex, in.buffer.getByte(id + (charlen - innerindex)));
-          innerindex-- ;
+        while (innerIndex > 0) {
+          out.buffer.setByte(index - innerIndex, in.buffer.getByte(id + (charLen - innerIndex)));
+          innerIndex--;
         }
 
-        index -= charlen;
+        index -= charLen;
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/72903d01/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
index daedd1c..fe099d7 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -19,12 +19,17 @@ package org.apache.drill.exec.expr.fn.impl;
 
 import static org.junit.Assert.assertTrue;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.drill.BaseTestQuery;
 import org.apache.drill.exec.util.Text;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
 public class TestStringFunctions extends BaseTestQuery {
 
   @Test
@@ -273,4 +278,34 @@ public class TestStringFunctions extends BaseTestQuery {
         .run();
   }
 
+  @Test
+  public void testReverse() throws Exception {
+    testBuilder()
+      .sqlQuery("select reverse('qwerty') words from (values(1))")
+      .unOrdered()
+      .baselineColumns("words")
+      .baselineValues("ytrewq")
+      .build()
+      .run();
+  }
+
+  @Test // DRILL-5424
+  public void testReverseLongVarChars() throws Exception {
+    File path = new File(BaseTestQuery.getTempDir("input"));
+    try {
+      path.mkdirs();
+      String pathString = path.toPath().toString();
+
+      try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path, "table_with_long_varchars.json"))))
{
+        for (int i = 0; i < 10; i++) {
+          writer.write("{ \"a\": \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\"}");
+        }
+      }
+
+      test("select reverse(a) from dfs_test.`%s/table_with_long_varchars.json` t", pathString);
+
+    } finally {
+      FileUtils.deleteQuietly(path);
+    }
+  }
 }


Mime
View raw message