DRILL-574: Fix RPAD to truncate from right, when desired length is smaller than input length.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/393adee7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/393adee7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/393adee7 Branch: refs/heads/master Commit: 393adee7e441cb5b03b4489e1497282c68ffbf52 Parents: 1726d73 Author: Mehant Baid <[email protected]> Authored: Thu Jun 5 00:22:42 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Thu Jun 5 09:37:04 2014 -0700 ---------------------------------------------------------------------- .../org/apache/drill/exec/expr/fn/impl/StringFunctions.java | 6 +++--- .../apache/drill/exec/physical/impl/TestStringFunctions.java | 2 +- .../java/org/apache/drill/jdbc/test/TestFunctionsQuery.java | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/393adee7/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 cebe491..8d792fa 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 @@ -627,10 +627,10 @@ public class StringFunctions{ out.start = text.start; out.end = text.end; } else if (length.value < textCharCount) { - //case 3: truncate text on left side, by (textCharCount - length.value) chars. + //case 3: truncate text on the right side. It's same as substring(text, 1, length). out.buffer = text.buffer; - out.start = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int) (textCharCount - length.value)); - out.end = text.end; + out.start = text.start; + out.end = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int)length.value); } else if (length.value > textCharCount) { //case 4: copy "text" into "out", then copy "fill" on the right. out.buffer = buffer; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/393adee7/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java index cd310b2..51aa633 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java @@ -222,7 +222,7 @@ public class TestStringFunctions extends ExecTest { @Test public void testRpad(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable{ - Object [] expected = new Object[] {"", "", "abcdef", "ef", "ef", "abcdef", "abcdefAAAA", "abcdefABAB", "abcdefABCA", "abcdefABCD"}; + Object [] expected = new Object[] {"", "", "abcdef", "ab", "ab", "abcdef", "abcdefAAAA", "abcdefABAB", "abcdefABCA", "abcdefABCD"}; runTest(bitContext, connection, expected, "functions/string/testRpad.json"); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/393adee7/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 c8f0d85..b5ca0b5 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 @@ -504,7 +504,8 @@ public class TestFunctionsQuery { @Test public void testPadFunctions() throws Exception { - String query = "select rpad(first_name, 10) as RPAD_DEF, rpad(first_name, 10, '*') as RPAD_STAR, lpad(first_name, 10) as LPAD_DEF, lpad(first_name, 10, '*') as LPAD_STAR " + + String query = "select rpad(first_name, 10) as RPAD_DEF, rpad(first_name, 10, '*') as RPAD_STAR, lpad(first_name, 10) as LPAD_DEF, lpad(first_name, 10, '*') as LPAD_STAR, " + + "lpad(first_name, 2) as LPAD_TRUNC, rpad(first_name, 2) as RPAD_TRUNC " + "from cp.`employee.json` where employee_id = 1"; JdbcAssert.withNoDefaultSchema() @@ -513,6 +514,8 @@ public class TestFunctionsQuery { "RPAD_DEF=Sheri ; " + "RPAD_STAR=Sheri*****; " + "LPAD_DEF= Sheri; " + - "LPAD_STAR=*****Sheri\n"); + "LPAD_STAR=*****Sheri; " + + "LPAD_TRUNC=Sh; " + + "RPAD_TRUNC=Sh\n"); } }
