Refine search
@Test public void testToIso8601ForTimestampWithoutTimeZone() { assertFunction("to_iso8601(" + TIMESTAMP_LITERAL + ")", createVarcharType(35), TIMESTAMP_ISO8601_STRING_NO_TIME_ZONE); }
@Test public void testEntryMappings() { assertFunction( "map_from_entries(map_entries(MAP(ARRAY[1, 2, 3], ARRAY['x', 'y', 'z'])))", mapType(INTEGER, createVarcharType(1)), ImmutableMap.of(1, "x", 2, "y", 3, "z")); assertFunction( "map_entries(map_from_entries(ARRAY[(1, 'x'), (2, 'y'), (3, 'z')]))", entryType(INTEGER, createVarcharType(1)), ImmutableList.of(ImmutableList.of(1, "x"), ImmutableList.of(2, "y"), ImmutableList.of(3, "z"))); }
private void validateMetadata(ExtendedHiveMetastore hiveMetastore) { assertEquals(hiveMetastore.getDatabase("database"), Optional.of(DATABASE)); assertEquals(hiveMetastore.getAllDatabases(), ImmutableList.of("database")); assertEquals(hiveMetastore.getTable("database", "table"), Optional.of(TABLE)); assertEquals(hiveMetastore.getSupportedColumnStatistics(createVarcharType(123)), ImmutableSet.of(MIN_VALUE, MAX_VALUE)); assertEquals(hiveMetastore.getTableStatistics("database", "table"), PARTITION_STATISTICS); assertEquals(hiveMetastore.getPartitionStatistics("database", "table", ImmutableSet.of("value")), ImmutableMap.of("value", PARTITION_STATISTICS)); assertEquals(hiveMetastore.getAllTables("database"), Optional.of(ImmutableList.of("table"))); assertEquals(hiveMetastore.getAllViews("database"), Optional.empty()); assertEquals(hiveMetastore.getPartition("database", "table", ImmutableList.of("value")), Optional.of(PARTITION)); assertEquals(hiveMetastore.getPartitionNames("database", "table"), Optional.of(ImmutableList.of("value"))); assertEquals(hiveMetastore.getPartitionNamesByParts("database", "table", ImmutableList.of("value")), Optional.of(ImmutableList.of("value"))); assertEquals(hiveMetastore.getPartitionsByNames("database", "table", ImmutableList.of("value")), ImmutableMap.of("value", Optional.of(PARTITION))); assertEquals(hiveMetastore.getRoles("user"), ImmutableSet.of("role1", "role2")); assertEquals(hiveMetastore.getDatabasePrivileges("user", "database"), ImmutableSet.of(PRIVILEGE_INFO)); assertEquals(hiveMetastore.getTablePrivileges("user", "database", "table"), ImmutableSet.of(PRIVILEGE_INFO)); }
@Test public void testRegexpExtractAll() { assertFunction("REGEXP_EXTRACT_ALL('rat cat\nbat dog', '.at')", new ArrayType(createVarcharType(15)), ImmutableList.of("rat", "cat", "bat")); assertFunction("REGEXP_EXTRACT_ALL('rat cat\nbat dog', '(.)at', 1)", new ArrayType(createVarcharType(15)), ImmutableList.of("r", "c", "b")); List<String> nullList = new ArrayList<>(); nullList.add(null); assertFunction("REGEXP_EXTRACT_ALL('rat cat\nbat dog', 'ra(.)|blah(.)(.)', 2)", new ArrayType(createVarcharType(15)), nullList); assertInvalidFunction("REGEXP_EXTRACT_ALL('hello', '(.)', 2)", "Pattern has 1 groups. Cannot access group 2"); assertFunction("REGEXP_EXTRACT_ALL('12345', '')", new ArrayType(createVarcharType(5)), ImmutableList.of("", "", "", "", "", "")); assertInvalidFunction("REGEXP_EXTRACT_ALL('12345', '(')", INVALID_FUNCTION_ARGUMENT); }
@Test public void testLiteral() { assertFunction("'foo'", createVarcharType(3), "foo"); assertFunction("'bar'", createVarcharType(3), "bar"); assertFunction("''", createVarcharType(0), ""); }
@Test public void testRegexpSplit() { assertFunction("REGEXP_SPLIT('a.b:c;d', '[\\.:;]')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b", "c", "d")); assertFunction("REGEXP_SPLIT('a.b:c;d', '\\.')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b:c;d")); assertFunction("REGEXP_SPLIT('a.b:c;d', ':')", new ArrayType(createVarcharType(7)), ImmutableList.of("a.b", "c;d")); assertFunction("REGEXP_SPLIT('a,b,c', ',')", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c")); assertFunction("REGEXP_SPLIT('a1b2c3d', '\\d')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b", "c", "d")); assertFunction("REGEXP_SPLIT('a1b2346c3d', '\\d+')", new ArrayType(createVarcharType(10)), ImmutableList.of("a", "b", "c", "d")); assertFunction("REGEXP_SPLIT('abcd', 'x')", new ArrayType(createVarcharType(4)), ImmutableList.of("abcd")); assertFunction("REGEXP_SPLIT('abcd', '')", new ArrayType(createVarcharType(4)), ImmutableList.of("", "a", "b", "c", "d", "")); assertFunction("REGEXP_SPLIT('', 'x')", new ArrayType(createVarcharType(0)), ImmutableList.of("")); // test empty splits, leading & trailing empty splits, consecutive empty splits assertFunction("REGEXP_SPLIT('a,b,c,d', ',')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b", "c", "d")); assertFunction("REGEXP_SPLIT(',,a,,,b,c,d,,', ',')", new ArrayType(createVarcharType(13)), ImmutableList.of("", "", "a", "", "", "b", "c", "d", "", "")); assertFunction("REGEXP_SPLIT(',,,', ',')", new ArrayType(createVarcharType(3)), ImmutableList.of("", "", "", "")); } }
@Test public void testCharToVarcharCast() { assertFunction("cast(cast('bar' as char(5)) as varchar(10))", createVarcharType(10), "bar "); assertFunction("cast(cast('bar' as char(5)) as varchar(1))", createVarcharType(1), "b"); assertFunction("cast(cast('b' as char(5)) as varchar(2))", createVarcharType(2), "b "); assertFunction("cast(cast('b' as char(5)) as varchar(1))", createVarcharType(1), "b"); assertFunction("cast(cast('bar' as char(3)) as varchar(3))", createVarcharType(3), "bar"); assertFunction("cast(cast('b' as char(3)) as varchar(3))", createVarcharType(3), "b "); }
@Test public void testDifferentLength() { assertFunction( "zip_with(ARRAY[1], ARRAY['a', 'bc'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(createVarcharType(2), INTEGER))), ImmutableList.of(ImmutableList.of("a", 1), asList("bc", null))); assertFunction( "zip_with(ARRAY[NULL, 2], ARRAY['a'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(createVarcharType(1), INTEGER))), ImmutableList.of(asList("a", null), asList(null, 2))); assertFunction( "zip_with(ARRAY[NULL, NULL], ARRAY[NULL, 2, 1], (x, y) -> x + y)", new ArrayType(INTEGER), asList(null, null, null)); }
@Test public void testToIso8601() { assertFunction("to_iso8601(" + WEIRD_TIMESTAMP_LITERAL + ")", createVarcharType(35), WEIRD_TIMESTAMP_ISO8601_STRING); assertFunction("to_iso8601(" + DATE_LITERAL + ")", createVarcharType(16), DATE_ISO8601_STRING); }
@Test public void ruleAddedTableLayoutToFilterTableScan() { Map<String, Domain> filterConstraint = ImmutableMap.<String, Domain>builder() .put("orderstatus", singleValue(createVarcharType(1), utf8Slice("F"))) .build(); tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()) .on(p -> p.filter(expression("orderstatus = CAST ('F' AS VARCHAR(1))"), p.tableScan( ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", createVarcharType(1))), ImmutableMap.of(p.symbol("orderstatus", createVarcharType(1)), new TpchColumnHandle("orderstatus", createVarcharType(1)))))) .matches( constrainedTableScanWithTableLayout("orders", filterConstraint, ImmutableMap.of("orderstatus", "orderstatus"))); }
@Test public void testToIso8601ForTimestampWithoutTimeZone() { assertFunction("to_iso8601(" + TIMESTAMP_LITERAL + ")", createVarcharType(35), TIMESTAMP_ISO8601_STRING); }
@Test public void eliminateTableScanWhenNoLayoutExist() { tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()) .on(p -> p.filter(expression("orderstatus = 'G'"), p.tableScan( ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", createVarcharType(1))), ImmutableMap.of(p.symbol("orderstatus", createVarcharType(1)), new TpchColumnHandle("orderstatus", createVarcharType(1))), Optional.of(ordersTableLayoutHandle)))) .matches(values("A")); }
@Test public void testUrlExtractParameter() { assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k2=v2&k3&k4#Ref1', 'k1')", createVarcharType(53), "v1"); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k2=v2&k3&k4#Ref1', 'k2')", createVarcharType(53), "v2"); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k2=v2&k3&k4#Ref1', 'k3')", createVarcharType(53), ""); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k2=v2&k3&k4#Ref1', 'k4')", createVarcharType(53), ""); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k2=v2&k3&k4#Ref1', 'k5')", createVarcharType(53), null); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1=v1&k1=v2&k1&k1#Ref1', 'k1')", createVarcharType(53), "v1"); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k1&k1=v1&k1&k1#Ref1', 'k1')", createVarcharType(50), ""); assertFunction("url_extract_parameter('http://example.com/path1/p.php?k=a=b=c&x=y#Ref1', 'k')", createVarcharType(47), "a=b=c"); assertFunction("url_extract_parameter('foo', 'k1')", createVarcharType(3), null); }
@Test public void testSearchCaseMultiple() throws Exception ImmutableList.of("double", "bigint", "double", "double")); assertExecute(expressions, createVarcharType(6), expected); ImmutableList.of("decimal(14,4)", "bigint", "decimal(14,4)", "double")); assertExecute(expressions, createVarcharType(6), expected);
@Test public void testLeftTrim() { assertFunction("LTRIM('')", createVarcharType(0), ""); assertFunction("LTRIM(' ')", createVarcharType(3), ""); assertFunction("LTRIM(' hello ')", createVarcharType(9), "hello "); assertFunction("LTRIM(' hello')", createVarcharType(7), "hello"); assertFunction("LTRIM('hello ')", createVarcharType(7), "hello "); assertFunction("LTRIM(' hello world ')", createVarcharType(13), "hello world "); assertFunction("LTRIM('\u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B "); assertFunction("LTRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B "); assertFunction("LTRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("LTRIM(' \u2028 \u4FE1\u5FF5 \u7231 \u5E0C\u671B')", createVarcharType(10), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); }
@Test public void testSplit() { assertFunction("SPLIT('a.b.c', '.')", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c")); assertFunction("SPLIT('ab', '.', 1)", new ArrayType(createVarcharType(2)), ImmutableList.of("ab")); assertFunction("SPLIT('a.b', '.', 1)", new ArrayType(createVarcharType(3)), ImmutableList.of("a.b")); assertFunction("SPLIT('a.b.c', '.')", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c")); assertFunction("SPLIT('a..b..c', '..')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b", "c")); assertFunction("SPLIT('a.b.c', '.', 2)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b.c")); assertFunction("SPLIT('a.b.c', '.', 3)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c")); assertFunction("SPLIT('a.b.c', '.', 4)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c")); assertFunction("SPLIT('a.b.c.', '.', 4)", new ArrayType(createVarcharType(6)), ImmutableList.of("a", "b", "c", "")); assertFunction("SPLIT('a.b.c.', '.', 3)", new ArrayType(createVarcharType(6)), ImmutableList.of("a", "b", "c.")); assertFunction("SPLIT('...', '.')", new ArrayType(createVarcharType(3)), ImmutableList.of("", "", "", "")); assertFunction("SPLIT('..a...a..', '.')", new ArrayType(createVarcharType(9)), ImmutableList.of("", "", "a", "", "", "a", "", "")); // Test SPLIT for non-ASCII assertFunction("SPLIT('\u4FE1\u5FF5,\u7231,\u5E0C\u671B', ',', 3)", new ArrayType(createVarcharType(7)), ImmutableList.of("\u4FE1\u5FF5", "\u7231", "\u5E0C\u671B")); assertFunction("SPLIT('\u8B49\u8BC1\u8A3C', '\u8BC1', 2)", new ArrayType(createVarcharType(3)), ImmutableList.of("\u8B49", "\u8A3C")); assertFunction("SPLIT('.a.b.c', '.', 4)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a", "b", "c")); assertFunction("SPLIT('.a.b.c', '.', 3)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a", "b.c")); assertFunction("SPLIT('.a.b.c', '.', 2)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a.b.c")); assertFunction("SPLIT('a..b..c', '.', 3)", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "", "b..c")); assertFunction("SPLIT('a.b..', '.', 3)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", ".")); assertInvalidFunction("SPLIT('a.b.c', '', 1)", "The delimiter may not be the empty string"); assertInvalidFunction("SPLIT('a.b.c', '.', 0)", "Limit must be positive"); assertInvalidFunction("SPLIT('a.b.c', '.', -1)", "Limit must be positive"); assertInvalidFunction("SPLIT('a.b.c', '.', 2147483648)", "Limit is too large"); }
@Test public void testRightTrim() { assertFunction("RTRIM('')", createVarcharType(0), ""); assertFunction("RTRIM(' ')", createVarcharType(3), ""); assertFunction("RTRIM(' hello ')", createVarcharType(9), " hello"); assertFunction("RTRIM(' hello')", createVarcharType(7), " hello"); assertFunction("RTRIM('hello ')", createVarcharType(7), "hello"); assertFunction("RTRIM(' hello world ')", createVarcharType(13), " hello world"); assertFunction("RTRIM('\u4FE1\u5FF5 \u7231 \u5E0C\u671B \u2028 ')", createVarcharType(10), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("RTRIM('\u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("RTRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), " \u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("RTRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B')", createVarcharType(9), " \u4FE1\u5FF5 \u7231 \u5E0C\u671B"); }
@Test public void ruleAddedNewTableLayoutIfTableScanHasEmptyConstraint() { tester().assertThat(pickTableLayout.pickTableLayoutForPredicate()) .on(p -> p.filter(expression("orderstatus = 'F'"), p.tableScan( ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", createVarcharType(1))), ImmutableMap.of(p.symbol("orderstatus", createVarcharType(1)), new TpchColumnHandle("orderstatus", createVarcharType(1))), Optional.of(ordersTableLayoutHandle)))) .matches( constrainedTableScanWithTableLayout( "orders", ImmutableMap.of("orderstatus", singleValue(createVarcharType(1), utf8Slice("F"))), ImmutableMap.of("orderstatus", "orderstatus"))); }
@Test public void testTrim() { assertFunction("TRIM('')", createVarcharType(0), ""); assertFunction("TRIM(' ')", createVarcharType(3), ""); assertFunction("TRIM(' hello ')", createVarcharType(9), "hello"); assertFunction("TRIM(' hello')", createVarcharType(7), "hello"); assertFunction("TRIM('hello ')", createVarcharType(7), "hello"); assertFunction("TRIM(' hello world ')", createVarcharType(13), "hello world"); assertFunction("TRIM('\u4FE1\u5FF5 \u7231 \u5E0C\u671B \u2028 ')", createVarcharType(10), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("TRIM('\u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("TRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B ')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("TRIM(' \u4FE1\u5FF5 \u7231 \u5E0C\u671B')", createVarcharType(9), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); assertFunction("TRIM(' \u2028 \u4FE1\u5FF5 \u7231 \u5E0C\u671B')", createVarcharType(10), "\u4FE1\u5FF5 \u7231 \u5E0C\u671B"); }
@Test public void testNull() { assertFunction("ngrams(ARRAY['foo', NULL, 'bar'], 2)", new ArrayType(new ArrayType(createVarcharType(3))), ImmutableList.of( asList("foo", null), asList(null, "bar"))); assertFunction("ngrams(ARRAY [NULL, NULL, NULL], 2)", new ArrayType(new ArrayType(UNKNOWN)), ImmutableList.of( asList(null, null), asList(null, null))); assertFunction("ngrams(ARRAY [NULL, 3, NULL], 2)", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of( asList(null, 3), asList(3, null))); }