Index: ql/src/test/results/clientpositive/udf_abs.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_abs.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_abs.q.out (revision 0) @@ -0,0 +1,100 @@ +query: EXPLAIN SELECT + abs(0), + abs(-1), + abs(123), + abs(-9223372036854775807), + abs(9223372036854775807) +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION abs 0)) (TOK_SELEXPR (TOK_FUNCTION abs (- 1))) (TOK_SELEXPR (TOK_FUNCTION abs 123)) (TOK_SELEXPR (TOK_FUNCTION abs (- 9223372036854775807))) (TOK_SELEXPR (TOK_FUNCTION abs 9223372036854775807))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: abs(0) + type: int + expr: abs(- 1) + type: int + expr: abs(123) + type: int + expr: abs(- 9223372036854775807) + type: bigint + expr: abs(9223372036854775807) + type: bigint + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + abs(0), + abs(-1), + abs(123), + abs(-9223372036854775807), + abs(9223372036854775807) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1522491061/10000 +0 1 123 9223372036854775807 9223372036854775807 +query: EXPLAIN SELECT + abs(0.0), + abs(-3.14159265), + abs(3.14159265) +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION abs 0.0)) (TOK_SELEXPR (TOK_FUNCTION abs (- 3.14159265))) (TOK_SELEXPR (TOK_FUNCTION abs 3.14159265))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: abs(0.0) + type: double + expr: abs(- 3.14159265) + type: double + expr: abs(3.14159265) + type: double + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + abs(0.0), + abs(-3.14159265), + abs(3.14159265) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/894722340/10000 +0.0 3.14159265 3.14159265 Index: ql/src/test/results/clientpositive/udf_split.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_split.q.out (revision 796913) +++ ql/src/test/results/clientpositive/udf_split.q.out (working copy) @@ -1,10 +1,11 @@ query: EXPLAIN SELECT split('a b c', ' '), split('oneAtwoBthreeC', '[ABC]'), - split('', '.') + split('', '.'), + split(50401020, 0) FROM src LIMIT 1 ABSTRACT SYNTAX TREE: - (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION split 'a b c' ' ')) (TOK_SELEXPR (TOK_FUNCTION split 'oneAtwoBthreeC' '[ABC]')) (TOK_SELEXPR (TOK_FUNCTION split '' '.'))) (TOK_LIMIT 1))) + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION split 'a b c' ' ')) (TOK_SELEXPR (TOK_FUNCTION split 'oneAtwoBthreeC' '[ABC]')) (TOK_SELEXPR (TOK_FUNCTION split '' '.')) (TOK_SELEXPR (TOK_FUNCTION split 50401020 0))) (TOK_LIMIT 1))) STAGE DEPENDENCIES: Stage-1 is a root stage @@ -17,12 +18,14 @@ src Select Operator expressions: - expr: SPLIT('a b c', ' ') + expr: split('a b c', ' ') type: array - expr: SPLIT('oneAtwoBthreeC', '[ABC]') + expr: split('oneAtwoBthreeC', '[ABC]') type: array - expr: SPLIT('', '.') + expr: split('', '.') type: array + expr: split(50401020, 0) + type: array Limit File Output Operator compressed: false @@ -39,8 +42,9 @@ query: SELECT split('a b c', ' '), split('oneAtwoBthreeC', '[ABC]'), - split('', '.') + split('', '.'), + split(50401020, 0) FROM src LIMIT 1 Input: default/src -Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/6715761/10000 -["a","b","c"] ["one","two","three"] [] +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1744248062/10000 +["a","b","c"] ["one","two","three"] [] ["5","4","1","2"] Index: ql/src/test/results/clientpositive/udf_substr.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_substr.q.out (revision 796913) +++ ql/src/test/results/clientpositive/udf_substr.q.out (working copy) @@ -4,7 +4,7 @@ substr('ABC', 1, null) FROM src LIMIT 1 Input: default/src -Output: /data/users/athusoo/commits/hive_trunk_ws8/ql/../build/ql/tmp/273310899/179583241.10000 +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1003484703/10000 NULL NULL NULL NULL NULL query: SELECT substr('ABC', 1, 0), substr('ABC', 1, -1), substr('ABC', 2, -100), @@ -15,7 +15,7 @@ substr('ABC', 2147483647), substr('ABC', 2147483647, 2147483647) FROM src LIMIT 1 Input: default/src -Output: /data/users/athusoo/commits/hive_trunk_ws8/ql/../build/ql/tmp/1187050376/77350002.10000 +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/250165013/10000 query: SELECT substr('ABCDEFG', 3, 4), substr('ABCDEFG', -5, 4), @@ -25,7 +25,7 @@ substr('A', 0), substr('A', 1), substr('A', -1) FROM src LIMIT 1 Input: default/src -Output: /data/users/athusoo/commits/hive_trunk_ws8/ql/../build/ql/tmp/663733434/1218000666.10000 +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1628096586/10000 CDEF CDEF CDEFG CDEFG ABC ABC BC C ABC BC A A A query: SELECT substr('ABC', 0, 1), substr('ABC', 0, 2), substr('ABC', 0, 3), substr('ABC', 0, 4), @@ -35,7 +35,7 @@ substr('ABC', 4, 1) FROM src LIMIT 1 Input: default/src -Output: /data/users/athusoo/commits/hive_trunk_ws8/ql/../build/ql/tmp/573014667/1237268671.10000 +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1508843983/10000 A AB ABC ABC A AB ABC ABC B BC BC BC C C C C query: SELECT substr('ABC', -1, 1), substr('ABC', -1, 2), substr('ABC', -1, 3), substr('ABC', -1, 4), @@ -44,5 +44,16 @@ substr('ABC', -4, 1) FROM src LIMIT 1 Input: default/src -Output: /data/users/athusoo/commits/hive_trunk_ws8/ql/../build/ql/tmp/265540324/810313953.10000 +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1953689668/10000 C C C C B BC BC BC A AB ABC ABC +query: -- substring() is a synonim of substr(), so just perform some basic tests +SELECT + substring('ABCDEFG', 3, 4), substring('ABCDEFG', -5, 4), + substring('ABCDEFG', 3), substring('ABCDEFG', -5), + substring('ABC', 0), substring('ABC', 1), substring('ABC', 2), substring('ABC', 3), + substring('ABC', 1, 2147483647), substring('ABC', 2, 2147483647), + substring('A', 0), substring('A', 1), substring('A', -1) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/17245713/10000 +CDEF CDEF CDEFG CDEFG ABC ABC BC C ABC BC A A A Index: ql/src/test/results/clientpositive/udf_space.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_space.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_space.q.out (revision 0) @@ -0,0 +1,64 @@ +query: EXPLAIN SELECT + space(10), + space(0), + space(1), + space(-1), + space(-100) +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION space 10)) (TOK_SELEXPR (TOK_FUNCTION space 0)) (TOK_SELEXPR (TOK_FUNCTION space 1)) (TOK_SELEXPR (TOK_FUNCTION space (- 1))) (TOK_SELEXPR (TOK_FUNCTION space (- 100)))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: space(10) + type: string + expr: space(0) + type: string + expr: space(1) + type: string + expr: space(- 1) + type: string + expr: space(- 100) + type: string + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + length(space(10)), + length(space(0)), + length(space(1)), + length(space(-1)), + length(space(-100)) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1667425937/10000 +10 0 1 0 0 +query: SELECT + space(10), + space(0), + space(1), + space(-1), + space(-100) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/540464301/10000 + Index: ql/src/test/results/clientpositive/udf_lpad_rpad.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_lpad_rpad.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_lpad_rpad.q.out (revision 0) @@ -0,0 +1,92 @@ +query: EXPLAIN SELECT + lpad('hi', 1, '?'), + lpad('hi', 5, '.'), + lpad('hi', 6, '123') +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION lpad 'hi' 1 '?')) (TOK_SELEXPR (TOK_FUNCTION lpad 'hi' 5 '.')) (TOK_SELEXPR (TOK_FUNCTION lpad 'hi' 6 '123'))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: lpad('hi', 1, '?') + type: string + expr: lpad('hi', 5, '.') + type: string + expr: lpad('hi', 6, '123') + type: string + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + lpad('hi', 1, '?'), + lpad('hi', 5, '.'), + lpad('hi', 6, '123') +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/328439542/10000 +h ...hi 1231hi +query: EXPLAIN SELECT + rpad('hi', 1, '?'), + rpad('hi', 5, '.'), + rpad('hi', 6, '123') +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION rpad 'hi' 1 '?')) (TOK_SELEXPR (TOK_FUNCTION rpad 'hi' 5 '.')) (TOK_SELEXPR (TOK_FUNCTION rpad 'hi' 6 '123'))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: rpad('hi', 1, '?') + type: string + expr: rpad('hi', 5, '.') + type: string + expr: rpad('hi', 6, '123') + type: string + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + rpad('hi', 1, '?'), + rpad('hi', 5, '.'), + rpad('hi', 6, '123') +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/368208834/10000 +h hi... hi1231 Index: ql/src/test/results/clientpositive/udf_repeat.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_repeat.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_repeat.q.out (revision 0) @@ -0,0 +1,50 @@ +query: EXPLAIN SELECT + repeat("Facebook", 3), + repeat("", 4), + repeat("asd", 0), + repeat("asdf", -1) +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION repeat "Facebook" 3)) (TOK_SELEXPR (TOK_FUNCTION repeat "" 4)) (TOK_SELEXPR (TOK_FUNCTION repeat "asd" 0)) (TOK_SELEXPR (TOK_FUNCTION repeat "asdf" (- 1)))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: repeat('Facebook', 3) + type: string + expr: repeat('', 4) + type: string + expr: repeat('asd', 0) + type: string + expr: repeat('asdf', - 1) + type: string + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + repeat("Facebook", 3), + repeat("", 4), + repeat("asd", 0), + repeat("asdf", -1) +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1180088338/10000 +FacebookFacebookFacebook Index: ql/src/test/results/clientpositive/udf_ascii.q.out =================================================================== --- ql/src/test/results/clientpositive/udf_ascii.q.out (revision 0) +++ ql/src/test/results/clientpositive/udf_ascii.q.out (revision 0) @@ -0,0 +1,46 @@ +query: EXPLAIN SELECT + ascii('Facebook'), + ascii(''), + ascii('!') +FROM src LIMIT 1 +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION ascii 'Facebook')) (TOK_SELEXPR (TOK_FUNCTION ascii '')) (TOK_SELEXPR (TOK_FUNCTION ascii '!'))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + Select Operator + expressions: + expr: ascii('Facebook') + type: int + expr: ascii('') + type: int + expr: ascii('!') + type: int + Limit + File Output Operator + compressed: false + GlobalTableId: 0 + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +query: SELECT + ascii('Facebook'), + ascii(''), + ascii('!') +FROM src LIMIT 1 +Input: default/src +Output: file:/data/users/emil/hive1/hive1/build/ql/tmp/1218831407/10000 +70 0 33 Index: ql/src/test/queries/clientpositive/udf_split.q =================================================================== --- ql/src/test/queries/clientpositive/udf_split.q (revision 796913) +++ ql/src/test/queries/clientpositive/udf_split.q (working copy) @@ -1,11 +1,13 @@ EXPLAIN SELECT split('a b c', ' '), split('oneAtwoBthreeC', '[ABC]'), - split('', '.') + split('', '.'), + split(50401020, 0) FROM src LIMIT 1; SELECT split('a b c', ' '), split('oneAtwoBthreeC', '[ABC]'), - split('', '.') + split('', '.'), + split(50401020, 0) FROM src LIMIT 1; Index: ql/src/test/queries/clientpositive/udf_space.q =================================================================== --- ql/src/test/queries/clientpositive/udf_space.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_space.q (revision 0) @@ -0,0 +1,24 @@ +EXPLAIN SELECT + space(10), + space(0), + space(1), + space(-1), + space(-100) +FROM src LIMIT 1; + +SELECT + length(space(10)), + length(space(0)), + length(space(1)), + length(space(-1)), + length(space(-100)) +FROM src LIMIT 1; + +SELECT + space(10), + space(0), + space(1), + space(-1), + space(-100) +FROM src LIMIT 1; + Index: ql/src/test/queries/clientpositive/udf_substr.q =================================================================== --- ql/src/test/queries/clientpositive/udf_substr.q (revision 796913) +++ ql/src/test/queries/clientpositive/udf_substr.q (working copy) @@ -35,3 +35,12 @@ substr('ABC', -3, 1), substr('ABC', -3, 2), substr('ABC', -3, 3), substr('ABC', -3, 4), substr('ABC', -4, 1) FROM src LIMIT 1; + +-- substring() is a synonim of substr(), so just perform some basic tests +SELECT + substring('ABCDEFG', 3, 4), substring('ABCDEFG', -5, 4), + substring('ABCDEFG', 3), substring('ABCDEFG', -5), + substring('ABC', 0), substring('ABC', 1), substring('ABC', 2), substring('ABC', 3), + substring('ABC', 1, 2147483647), substring('ABC', 2, 2147483647), + substring('A', 0), substring('A', 1), substring('A', -1) +FROM src LIMIT 1; Index: ql/src/test/queries/clientpositive/udf_repeat.q =================================================================== --- ql/src/test/queries/clientpositive/udf_repeat.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_repeat.q (revision 0) @@ -0,0 +1,13 @@ +EXPLAIN SELECT + repeat("Facebook", 3), + repeat("", 4), + repeat("asd", 0), + repeat("asdf", -1) +FROM src LIMIT 1; + +SELECT + repeat("Facebook", 3), + repeat("", 4), + repeat("asd", 0), + repeat("asdf", -1) +FROM src LIMIT 1; Index: ql/src/test/queries/clientpositive/udf_abs.q =================================================================== --- ql/src/test/queries/clientpositive/udf_abs.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_abs.q (revision 0) @@ -0,0 +1,27 @@ +EXPLAIN SELECT + abs(0), + abs(-1), + abs(123), + abs(-9223372036854775807), + abs(9223372036854775807) +FROM src LIMIT 1; + +SELECT + abs(0), + abs(-1), + abs(123), + abs(-9223372036854775807), + abs(9223372036854775807) +FROM src LIMIT 1; + +EXPLAIN SELECT + abs(0.0), + abs(-3.14159265), + abs(3.14159265) +FROM src LIMIT 1; + +SELECT + abs(0.0), + abs(-3.14159265), + abs(3.14159265) +FROM src LIMIT 1; Index: ql/src/test/queries/clientpositive/udf_ascii.q =================================================================== --- ql/src/test/queries/clientpositive/udf_ascii.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_ascii.q (revision 0) @@ -0,0 +1,11 @@ +EXPLAIN SELECT + ascii('Facebook'), + ascii(''), + ascii('!') +FROM src LIMIT 1; + +SELECT + ascii('Facebook'), + ascii(''), + ascii('!') +FROM src LIMIT 1; Index: ql/src/test/queries/clientpositive/udf_lpad_rpad.q =================================================================== --- ql/src/test/queries/clientpositive/udf_lpad_rpad.q (revision 0) +++ ql/src/test/queries/clientpositive/udf_lpad_rpad.q (revision 0) @@ -0,0 +1,23 @@ +EXPLAIN SELECT + lpad('hi', 1, '?'), + lpad('hi', 5, '.'), + lpad('hi', 6, '123') +FROM src LIMIT 1; + +SELECT + lpad('hi', 1, '?'), + lpad('hi', 5, '.'), + lpad('hi', 6, '123') +FROM src LIMIT 1; + +EXPLAIN SELECT + rpad('hi', 1, '?'), + rpad('hi', 5, '.'), + rpad('hi', 6, '123') +FROM src LIMIT 1; + +SELECT + rpad('hi', 1, '?'), + rpad('hi', 5, '.'), + rpad('hi', 6, '123') +FROM src LIMIT 1; Index: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (revision 796913) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (working copy) @@ -53,7 +53,13 @@ mFunctions = new HashMap(); registerUDF("concat", UDFConcat.class, OperatorType.PREFIX, false); registerUDF("substr", UDFSubstr.class, OperatorType.PREFIX, false); - + registerUDF("substring", UDFSubstr.class, OperatorType.PREFIX, false); + registerUDF("space", UDFSpace.class, OperatorType.PREFIX, false); + registerUDF("repeat", UDFRepeat.class, OperatorType.PREFIX, false); + registerUDF("ascii", UDFAscii.class, OperatorType.PREFIX, false); + registerUDF("lpad", UDFLpad.class, OperatorType.PREFIX, false); + registerUDF("rpad", UDFRpad.class, OperatorType.PREFIX, false); + registerGenericUDF("size", GenericUDFSize.class); registerUDF("round", UDFRound.class, OperatorType.PREFIX, false); @@ -62,6 +68,7 @@ registerUDF("ceil", UDFCeil.class, OperatorType.PREFIX, false); registerUDF("ceiling", UDFCeil.class, OperatorType.PREFIX, false); registerUDF("rand", UDFRand.class, OperatorType.PREFIX, false); + registerUDF("abs", UDFAbs.class, OperatorType.PREFIX, false); registerUDF("ln", UDFLn.class, OperatorType.PREFIX, false); registerUDF("log2", UDFLog2.class, OperatorType.PREFIX, false); Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java (revision 0) @@ -0,0 +1,61 @@ +/** + * 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.hadoop.hive.ql.udf; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.IntWritable; + +public class UDFAbs extends UDF { + + private DoubleWritable resultDouble = new DoubleWritable(); + private LongWritable resultLong = new LongWritable(); + private IntWritable resultInt = new IntWritable(); + + public DoubleWritable evaluate(DoubleWritable n) { + if (n == null) { + return null; + } + + resultDouble.set(Math.abs(n.get())); + + return resultDouble; + } + + public LongWritable evaluate(LongWritable n) { + if (n == null) { + return null; + } + + resultLong.set(Math.abs(n.get())); + + return resultLong; + } + + public IntWritable evaluate(IntWritable n) { + if (n == null) { + return null; + } + + resultInt.set(Math.abs(n.get())); + + return resultInt; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java (revision 796913) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java (working copy) @@ -29,8 +29,11 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector; import org.apache.hadoop.io.Text; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters; public class GenericUDFSplit extends GenericUDF { + private ObjectInspectorConverters.Converter[] converters; + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { @@ -38,14 +41,11 @@ "The function SPLIT(s, regexp) takes exactly 2 arguments."); } - if(!(arguments[0] instanceof WritableStringObjectInspector)) { - throw new UDFArgumentTypeException(0, - "Arguments of SPLIT(s, regexp) must be strings."); + converters = new ObjectInspectorConverters.Converter[arguments.length]; + for(int i = 0; i < arguments.length; i++) { + converters[i] = ObjectInspectorConverters.getConverter(arguments[i], + PrimitiveObjectInspectorFactory.writableStringObjectInspector); } - if(!(arguments[1] instanceof WritableStringObjectInspector)) { - throw new UDFArgumentTypeException(1, - "Arguments of SPLIT(s, regexp) must be strings."); - } return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableStringObjectInspector); @@ -58,10 +58,8 @@ return null; } - Text s = PrimitiveObjectInspectorFactory.writableStringObjectInspector - .getPrimitiveWritableObject(arguments[0].get()); - Text regex = PrimitiveObjectInspectorFactory.writableStringObjectInspector - .getPrimitiveWritableObject(arguments[1].get()); + Text s = (Text)converters[0].convert(arguments[0].get()); + Text regex = (Text)converters[1].convert(arguments[1].get()); ArrayList result = new ArrayList(); @@ -74,7 +72,7 @@ public String getDisplayString(String[] children) { assert(children.length == 2); - return "SPLIT(" + children[0] + ", " + children[1] + ")"; + return "split(" + children[0] + ", " + children[1] + ")"; } } Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLpad.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLpad.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLpad.java (revision 0) @@ -0,0 +1,62 @@ +/** + * 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.hadoop.hive.ql.udf; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class UDFLpad extends UDF { + + private Text result = new Text(); + + public Text evaluate(Text s, IntWritable n, Text pad) { + if (s == null || n == null || pad == null) { + return null; + } + + int len = n.get(); + + byte[] data = result.getBytes(); + if(data.length < len) { + data = new byte[len]; + } + + byte[] txt = s.getBytes(); + byte[] padTxt = pad.getBytes(); + + // The length of the padding needed + int pos = Math.max(len - s.getLength(), 0); + + // Copy the padding + for(int i = 0; i < pos; i += pad.getLength()) { + for(int j = 0; j < pad.getLength() && j < pos-i; j++) { + data[i+j] = padTxt[j]; + } + } + + // Copy the text + for(int i = 0; pos+i < len && i < s.getLength(); i++) { + data[pos+i] = txt[i]; + } + + result.set(data, 0, len); + return result; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java (revision 0) @@ -0,0 +1,61 @@ +/** + * 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.hadoop.hive.ql.udf; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class UDFRpad extends UDF { + + private Text result = new Text(); + + public Text evaluate(Text s, IntWritable n, Text pad) { + if (s == null || n == null || pad == null) { + return null; + } + + int len = n.get(); + + byte[] data = result.getBytes(); + if(data.length < len) { + data = new byte[len]; + } + + byte[] txt = s.getBytes(); + byte[] padTxt = pad.getBytes(); + + int pos; + // Copy the text + for(pos = 0; pos < s.getLength() && pos < len; pos++) { + data[pos] = txt[pos]; + } + + // Copy the padding + while(pos < len) { + for(int i = 0; i < pad.getLength() && i < len-pos; i++) { + data[pos+i] = padTxt[i]; + } + pos += pad.getLength(); + } + + result.set(data, 0, len); + return result; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java (revision 0) @@ -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.hadoop.hive.ql.udf; + +import java.util.Arrays; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class UDFRepeat extends UDF { + private Text result = new Text(); + + public Text evaluate(Text s, IntWritable n) { + if (n == null || s == null) { + return null; + } + + int len = n.get()*s.getLength(); + if(len < 0) { + len = 0; + } + + byte[] data = result.getBytes(); + + if(data.length < len) { + data = new byte[len]; + } + + for(int i = 0; i < len; i += s.getLength()) { + for(int j = 0; j < s.getLength(); j++) { + data[i + j] = s.getBytes()[j]; + } + } + + result.set(data, 0, len); + return result; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAscii.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAscii.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAscii.java (revision 0) @@ -0,0 +1,42 @@ +/** + * 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.hadoop.hive.ql.udf; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class UDFAscii extends UDF { + + private IntWritable result = new IntWritable(); + + public IntWritable evaluate(Text s) { + if (s == null) { + return null; + } + + if(s.getLength() > 0) { + result.set(s.getBytes()[0]); + } else { + result.set(0); + } + + return result; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java (revision 0) @@ -0,0 +1,51 @@ +/** + * 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.hadoop.hive.ql.udf; + +import java.util.Arrays; + +import org.apache.hadoop.hive.ql.exec.UDF; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class UDFSpace extends UDF { + private Text result = new Text(); + + public Text evaluate(IntWritable n) { + if (n == null) { + return null; + } + + int len = n.get(); + if(len < 0) { + len = 0; + } + + if(result.getBytes().length >= len) { + result.set(result.getBytes(), 0, len); + } + else { + byte[] spaces = new byte[len]; + Arrays.fill(spaces, (byte)' '); + result.set(spaces); + } + + return result; + } +}