Saving all output to "!!{outputDirectory}!!/udf_conv.q.raw". Enter "record" with no arguments to stop it. >>> !run !!{qFileDirectory}!!/udf_conv.q >>> DESCRIBE FUNCTION conv; 'tab_name' 'conv(num, from_base, to_base) - convert num from from_base to to_base' 1 row selected >>> DESCRIBE FUNCTION EXTENDED conv; 'tab_name' 'conv(num, from_base, to_base) - convert num from from_base to to_base' 'If to_base is negative, treat num as a signed integer,otherwise, treat it as an unsigned integer.' 'Example:' ' > SELECT conv('100', 2, 10) FROM src LIMIT 1;' ' '4'' ' > SELECT conv(-10, 16, -10) FROM src LIMIT 1;' ' '16'' 7 rows selected >>> >>> -- conv must work on both strings and integers up to 64-bit precision >>> >>> -- Some simple conversions to test different bases >>> SELECT conv('4521', 10, 36), conv('22', 10, 10), conv('110011', 2, 16), conv('facebook', 36, 16) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' '3HL','22','33','116ED2B2FB4' 1 row selected >>> >>> -- Test negative numbers. If to_base is positive, the number should be handled >>> -- as a two's complement (64-bit) >>> SELECT conv('-641', 10, -10), conv('1011', 2, -16), conv('-1', 10, 16), conv('-15', 10, 16) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' '-641','B','FFFFFFFFFFFFFFFF','FFFFFFFFFFFFFFF1' 1 row selected >>> >>> -- Test overflow. If a number is two large, the result should be -1 (if signed) >>> -- or MAX_LONG (if unsigned) >>> SELECT conv('9223372036854775807', 36, 16), conv('9223372036854775807', 36, -16), conv('-9223372036854775807', 36, 16), conv('-9223372036854775807', 36, -16) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' 'FFFFFFFFFFFFFFFF','-1','FFFFFFFFFFFFFFFF','-1' 1 row selected >>> >>> -- Test with invalid input. If one of the bases is invalid, the result should >>> -- be NULL. If there is an invalid digit in the number, the longest valid >>> -- prefix should be converted. >>> SELECT conv('123455', 3, 10), conv('131', 1, 5), conv('515', 5, 100), conv('10', -2, 2) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' '5','','','' 1 row selected >>> >>> -- Perform the same tests with number arguments. >>> >>> SELECT conv(4521, 10, 36), conv(22, 10, 10), conv(110011, 2, 16) FROM src LIMIT 1; '_c0','_c1','_c2' '3HL','22','33' 1 row selected >>> >>> SELECT conv(-641, 10, -10), conv(1011, 2, -16), conv(-1, 10, 16), conv(-15, 10, 16) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' '-641','B','FFFFFFFFFFFFFFFF','FFFFFFFFFFFFFFF1' 1 row selected >>> >>> SELECT conv(9223372036854775807, 36, 16), conv(9223372036854775807, 36, -16), conv(-9223372036854775807, 36, 16), conv(-9223372036854775807, 36, -16) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' 'FFFFFFFFFFFFFFFF','-1','FFFFFFFFFFFFFFFF','-1' 1 row selected >>> >>> SELECT conv(123455, 3, 10), conv(131, 1, 5), conv(515, 5, 100), conv('10', -2, 2) FROM src LIMIT 1; '_c0','_c1','_c2','_c3' '5','','','' 1 row selected >>> >>> -- Make sure that state is properly reset. >>> >>> SELECT conv(key, 10, 16), conv(key, 16, 10) FROM src LIMIT 3; '_c0','_c1' 'EE','568' '56','134' '137','785' 3 rows selected >>> !record