Here are the examples of the java api org.apache.drill.PlanTestBase.testPlanMatchingPatterns() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
83 Examples
19
Source : TestWindowFunctions.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-3404
@Test
public void testWindowSumAggIsNotNull() throws Exception {
String query = String.format("select count(*) cnt from (select sum ( c1 ) over ( parreplacedion by c2 order by c1 asc nulls first ) w_sum from dfs.`%s/window/table_with_nulls.parquet` ) sub_query where w_sum is not null", TEST_RES_PATH);
// Validate the plan
final String[] expectedPlan = { "Window.*parreplacedion \\{1\\} order by \\[0 ASC-nulls-first\\].*SUM\\(\\$0\\)", "Scan.*columns=\\[`c1`, `c2`\\]" };
final String[] excludedPatterns = { "Scan.*columns=\\[`\\*`\\]" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
testBuilder().sqlQuery(query).ordered().baselineColumns("cnt").baselineValues(26l).build().run();
}
19
Source : TestWindowFunctions.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-2330
@Test
public void testNestedAggregates() throws Exception {
final String query = "select sum(min(l_extendedprice))" + " over (parreplacedion by l_suppkey order by l_suppkey) as totprice" + " from cp.`tpch/lineitem.parquet` where l_suppkey <= 10 group by l_suppkey order by 1 desc";
// Validate the plan
final String[] expectedPlan = { "Window.*parreplacedion \\{0\\} order by \\[0\\].*SUM\\(\\$1\\).*", "HashAgg\\(group=\\[\\{0\\}\\].*\\[MIN\\(\\$1\\)\\]\\)" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[] {});
// Validate the results
testBuilder().sqlQuery(query).unOrdered().baselineColumns("totprice").baselineValues(1107.2).baselineValues(998.09).baselineValues(957.05).baselineValues(953.05).baselineValues(931.03).baselineValues(926.02).baselineValues(909.0).baselineValues(906.0).baselineValues(904.0).baselineValues(904.0).go();
}
19
Source : TestWindowFunctions.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-3196
@Test
public void testSingleParreplacedion() throws Exception {
final String query = "select sum(n_nationKey) over(parreplacedion by n_nationKey) as col1, count(*) over(parreplacedion by n_nationKey) as col2 \n" + "from cp.`tpch/nation.parquet`";
// Validate the plan
final String[] expectedPlan = { "Window.*parreplacedion \\{0\\} order by \\[\\].*\\[SUM\\(\\$0\\), COUNT\\(\\)", "Scan.*columns=\\[`n_nationKey`\\].*" };
final String[] excludedPatterns = { "Scan.*columns=\\[`\\*`\\].*" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
testBuilder().sqlQuery(query).unOrdered().baselineColumns("col1", "col2").baselineValues(0l, 1l).baselineValues(1l, 1l).baselineValues(2l, 1l).baselineValues(3l, 1l).baselineValues(4l, 1l).baselineValues(5l, 1l).baselineValues(6l, 1l).baselineValues(7l, 1l).baselineValues(8l, 1l).baselineValues(9l, 1l).baselineValues(10l, 1l).baselineValues(11l, 1l).baselineValues(12l, 1l).baselineValues(13l, 1l).baselineValues(14l, 1l).baselineValues(15l, 1l).baselineValues(16l, 1l).baselineValues(17l, 1l).baselineValues(18l, 1l).baselineValues(19l, 1l).baselineValues(20l, 1l).baselineValues(21l, 1l).baselineValues(22l, 1l).baselineValues(23l, 1l).baselineValues(24l, 1l).build().run();
}
19
Source : TestWindowFunctions.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-3196
@Test
public void testSingleParreplacedionDefinedInWindowList() throws Exception {
final String query = "select sum(n_nationKey) over w as col \n" + "from cp.`tpch/nation.parquet` \n" + "window w as (parreplacedion by n_nationKey order by n_nationKey)";
// Validate the plan
final String[] expectedPlan = { "Window.*parreplacedion \\{0\\} order by \\[0\\].*SUM\\(\\$0\\)", "Scan.*columns=\\[`n_nationKey`\\].*" };
final String[] excludedPatterns = { "Scan.*columns=\\[`\\*`\\].*" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
testBuilder().sqlQuery(query).unOrdered().baselineColumns("col").baselineValues(0l).baselineValues(1l).baselineValues(2l).baselineValues(3l).baselineValues(4l).baselineValues(5l).baselineValues(6l).baselineValues(7l).baselineValues(8l).baselineValues(9l).baselineValues(10l).baselineValues(11l).baselineValues(12l).baselineValues(13l).baselineValues(14l).baselineValues(15l).baselineValues(16l).baselineValues(17l).baselineValues(18l).baselineValues(19l).baselineValues(20l).baselineValues(21l).baselineValues(22l).baselineValues(23l).baselineValues(24l).build().run();
}
19
Source : TestParquetMetadataCache.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-4530 // non-existent parreplacedion (1 subdirectory's cache file will still be read for schema)
@Test
public void testDrill4530_4() throws Exception {
// create metadata cache
test(String.format("refresh table metadata dfs_test.`%s/%s`", getDfsTestTmpSchemaLocation(), tableName2));
checkForMetadataFile(tableName2);
// run query and check correctness
String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/%s` " + " where dir0=1995 and dir1='Q6'", getDfsTestTmpSchemaLocation(), tableName2);
int expectedRowCount = 0;
int expectedNumFiles = 1;
int actualRowCount = testSql(query1);
replacedertEquals(expectedRowCount, actualRowCount);
String numFilesPattern = "numFiles=" + expectedNumFiles;
String usedMetaPattern = "usedMetadataFile=true";
String cacheFileRootPattern = String.format("cacheFileRoot=%s/%s/*/*", getDfsTestTmpSchemaLocation(), tableName2);
PlanTestBase.testPlanMatchingPatterns(query1, new String[] { numFilesPattern, usedMetaPattern, cacheFileRootPattern }, new String[] {});
}
19
Source : TestParquetMetadataCache.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-4264
@Test
public void testMetadataCacheFieldWithDots() throws Exception {
final String tableWithDots = "dfs_test.tmp.`complex_table`";
try {
test("create table %s as\n" + "select cast(1 as int) as `column.with.dots`, t.`column`.`with.dots`\n" + "from cp.`store/parquet/complex/complex.parquet` t limit 1", tableWithDots);
String query = String.format("select * from %s", tableWithDots);
int expectedRowCount = 1;
int actualRowCount = testSql(query);
replacedertEquals("Row count does not match the expected value", expectedRowCount, actualRowCount);
PlanTestBase.testPlanMatchingPatterns(query, new String[] { "usedMetadataFile=false" }, null);
test("refresh table metadata %s", tableWithDots);
actualRowCount = testSql(query);
replacedertEquals("Row count does not match the expected value", expectedRowCount, actualRowCount);
PlanTestBase.testPlanMatchingPatterns(query, new String[] { "usedMetadataFile=true" }, null);
} finally {
test(String.format("drop table if exists %s", tableWithDots));
}
}
19
Source : TestParquetMetadataCache.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-4530 // single leaf level parreplacedion
@Test
public void testDrill4530_1() throws Exception {
// create metadata cache
test(String.format("refresh table metadata dfs_test.`%s/%s`", getDfsTestTmpSchemaLocation(), tableName2));
checkForMetadataFile(tableName2);
// run query and check correctness
String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/%s` " + " where dir0=1995 and dir1='Q3'", getDfsTestTmpSchemaLocation(), tableName2);
int expectedRowCount = 20;
int expectedNumFiles = 2;
int actualRowCount = testSql(query1);
replacedertEquals(expectedRowCount, actualRowCount);
String numFilesPattern = "numFiles=" + expectedNumFiles;
String usedMetaPattern = "usedMetadataFile=true";
String cacheFileRootPattern = String.format("cacheFileRoot=%s/%s/1995/Q3", getDfsTestTmpSchemaLocation(), tableName2);
PlanTestBase.testPlanMatchingPatterns(query1, new String[] { numFilesPattern, usedMetaPattern, cacheFileRootPattern }, new String[] { "Filter" });
}
19
Source : TestParquetFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-5359
@Test
public void testFilterWithItemFlatten() throws Exception {
final String sql = "select n_regionkey\n" + "from (select n_regionkey, \n" + " flatten(nation.cities) as cities \n" + " from cp.`tpch/nation.parquet` nation) as flattenedCities \n" + "where flattenedCities.cities.`zip` = '12345'";
final String[] expectedPlan = { "(?s)Filter.*Flatten" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestLimitWithExchanges.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
private void testLimitHelper(final String sql, final String[] expectedPlan, final String[] excludedPattern, int expectedRecordCount) throws Exception {
// Validate the plan
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPattern);
// Validate row count
final int actualRecordCount = testSql(sql);
replacedertEquals(String.format("Received unexpected number of rows in output: expected=%d, received=%s", expectedRecordCount, actualRecordCount), expectedRecordCount, actualRecordCount);
}
19
Source : TestEarlyLimit0Optimization.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
private static void checkThatQueryPlanIsOptimized(final String query) throws Exception {
PlanTestBase.testPlanMatchingPatterns(wrapLimit0(query), new String[] { ".*Project.*\n" + ".*Scan.*RelDataTypeReader.*" }, new String[] {});
}
19
Source : TestFlattenPlanning.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-4121 : push partial filter past projects : neg test case
@Test
public void testPushFilterPastProjectWithFlattenNeg() throws Exception {
final String query = " select comp, rownum " + " from (select flatten(complex) comp, rownum " + " from cp.`/store/json/test_flatten_mappify2.json`) " + // should NOT be pushed down
" where comp > 1 " + // should NOT be pushed down.
" OR rownum = 100";
final String[] expectedPlans = { "(?s)Filter.*OR.*Flatten" };
final String[] excludedPlans = { "(?s)Filter.*Flatten.*Filter.*" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlans, excludedPlans);
}
19
Source : TestFlattenPlanning.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-4121 : push partial filter past projects.
@Test
public void testPushFilterPastProjectWithFlatten() throws Exception {
final String query = " select comp, rownum " + " from (select flatten(complex) comp, rownum " + " from cp.`/store/json/test_flatten_mappify2.json`) " + // should not be pushed down
" where comp > 1 " + // should be pushed down.
" and rownum = 100";
final String[] expectedPlans = { "(?s)Filter.*>.*Flatten.*Filter.*=.*" };
final String[] excludedPlans = { "Filter.*AND.*" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlans, excludedPlans);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyRangeAndColumnValueLike() throws Exception {
setColumnWidths(new int[] { 8, 22 });
final String sql = "SELECT\n" + " row_key, convert_from(tableName.f.c, 'UTF8') `f.c`\n" + "FROM\n" + " hbase.`TestTable3` tableName\n" + "WHERE\n" + " row_key >= '07' AND row_key < '09' AND tableName.f.c LIKE 'value 0%9'";
runHBaseSQLVerifyCount(sql, 22);
final String[] expectedPlan = { ".*startRow=07, stopRow=09, filter=FilterList AND.*RowFilter \\(GREATER_OR_EQUAL, 07\\), RowFilter \\(LESS, 09\\), SingleColumnValueFilter \\(f, c, EQUAL.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyEqualWithItem() throws Exception {
setColumnWidths(new int[] { 20, 30 });
final String sql = "SELECT\n" + " cast(tableName.row_key as varchar(20)), cast(tableName.f.c1 as varchar(30))\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key = 'b4'";
runHBaseSQLVerifyCount(sql, 1);
final String[] expectedPlan = { ".*startRow=b4, stopRow=b4\\\\x00, filter=null.*" };
final String[] excludedPlan = { ".*startRow=null, stopRow=null.*" };
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyLikeWithEscape() throws Exception {
setColumnWidths(new int[] { 8, 22 });
final String sql = "SELECT\n" + " row_key, convert_from(tableName.f.c, 'UTF8') `f.c`\n" + "FROM\n" + " hbase.`TestTable3` tableName\n" + "WHERE\n" + " row_key LIKE '!%!_AS!_PREFIX!_%' ESCAPE '!'";
runHBaseSQLVerifyCount(sql, 2);
final String[] expectedPlan = { ".*startRow=\\%_AS_PREFIX_, stopRow=\\%_AS_PREFIX`, filter=RowFilter.*EQUAL.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownOrRowKeyEqual() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key = 'b4' or row_key = 'a2'";
runHBaseSQLVerifyCount(sql, 2);
final String[] expectedPlan = { ".*startRow=a2, stopRow=b4\\\\x00, filter=FilterList OR \\(2/2\\): \\[RowFilter \\(EQUAL, b4\\), RowFilter \\(EQUAL, a2\\).*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyLessThanOrEqualTo() throws Exception {
setColumnWidths(new int[] { 8, 74, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " 'b4' >= row_key";
runHBaseSQLVerifyCount(sql, 4);
final String[] expectedPlan = { ".*startRow=, stopRow=b4\\\\x00, filter=null.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownOrRowKeyInPred() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key in ('b4', 'a2')";
runHBaseSQLVerifyCount(sql, 2);
final String[] expectedPlan = { ".*startRow=a2, stopRow=b4\\\\x00, filter=FilterList OR \\(2/2\\): \\[RowFilter \\(EQUAL, b4\\), RowFilter \\(EQUAL, a2\\).*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownMultiColumnsWithItem() throws Exception {
setColumnWidths(new int[] { 8, 8 });
final String sql = "SELECT\n" + " row_key, t.f.c1\n" + "FROM\n" + " hbase.`[TABLE_NAME]` t\n" + "WHERE\n" + " (row_key >= 'b5' OR row_key <= 'a2') AND (t.f.c1 >= '1' OR t.f.c1 is null)";
final String[] expectedPlan = { ".*startRow=, stopRow=, filter=FilterList OR.*GREATER_OR_EQUAL, b5.*LESS_OR_EQUAL, a2.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyGreaterThan() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key > 'b4'";
runHBaseSQLVerifyCount(sql, 4);
final String[] expectedPlan = { ".*startRow=b4\\\\x00.*stopRow=,.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownMultiColumns() throws Exception {
setColumnWidths(new int[] { 8, 74, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` t\n" + "WHERE\n" + " (row_key >= 'b5' OR row_key <= 'a2') AND (t.f.c1 >= '1' OR t.f.c1 is null)";
runHBaseSQLVerifyCount(sql, 5);
final String[] expectedPlan = { ".*startRow=, stopRow=, filter=FilterList OR.*GREATER_OR_EQUAL, b5.*LESS_OR_EQUAL, a2.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyBetween() throws Exception {
setColumnWidths(new int[] { 8, 74, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key BETWEEN 'a2' AND 'b4'";
runHBaseSQLVerifyCount(sql, 3);
final String[] expectedPlan = { ".*startRow=a2, stopRow=b4\\\\x00, filter=FilterList AND.*GREATER_OR_EQUAL, a2.*LESS_OR_EQUAL, b4.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyLike() throws Exception {
setColumnWidths(new int[] { 8, 22 });
final String sql = "SELECT\n" + " row_key, convert_from(tableName.f.c, 'UTF8') `f.c`\n" + "FROM\n" + " hbase.`TestTable3` tableName\n" + "WHERE\n" + " row_key LIKE '08%0' OR row_key LIKE '%70'";
runHBaseSQLVerifyCount(sql, 21);
final String[] expectedPlan = { ".*filter=FilterList OR.*EQUAL.*EQUAL.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownOrRowKeyEqualRangePred() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key = 'a2' or row_key between 'b5' and 'b6'";
runHBaseSQLVerifyCount(sql, 3);
final String[] expectedPlan = { ".*startRow=a2, stopRow=b6\\\\x00, filter=FilterList OR \\(2/2\\): \\[RowFilter \\(EQUAL, a2\\), FilterList AND \\(2/2\\): \\[RowFilter \\(GREATER_OR_EQUAL, b5\\), RowFilter \\(LESS_OR_EQUAL, b6.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownConvertExpression() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " convert_from(row_key, 'UTF8') > 'b4'";
runHBaseSQLVerifyCount(sql, 4);
final String[] expectedPlan = { ".*startRow=b4\\\\x00, stopRow=,.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyGreaterThanWithItem() throws Exception {
setColumnWidths(new int[] { 8, 38 });
final String sql = "SELECT\n" + " row_key, tableName.f2.c3\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key > 'b4'";
runHBaseSQLVerifyCount(sql, 2);
final String[] expectedPlan = { ".*startRow=b4\\\\x00.*stopRow=, filter=null.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyEqual() throws Exception {
setColumnWidths(new int[] { 8, 38, 38 });
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key = 'b4'";
runHBaseSQLVerifyCount(sql, 1);
final String[] expectedPlan = { ".*startRow=b4, stopRow=b4\\\\x00, filter=null.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyLessThanOrEqualToWithItem() throws Exception {
setColumnWidths(new int[] { 8, 12 });
final String sql = "SELECT\n" + " row_key, tableName.f.c1\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " 'b4' >= row_key";
runHBaseSQLVerifyCount(sql, 4);
final String[] expectedPlan = { ".*startRow=, stopRow=b4\\\\x00, filter=null.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownConvertExpressionWithItem() throws Exception {
setColumnWidths(new int[] { 8, 38 });
final String sql = "SELECT\n" + " row_key, tableName.f2.c3\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " convert_from(row_key, 'UTF8') > 'b4'";
runHBaseSQLVerifyCount(sql, 2);
final String[] expectedPlan = { ".*startRow=b4\\\\x00, stopRow=,.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestHBaseFilterPushDown.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testFilterPushDownRowKeyBetweenWithItem() throws Exception {
setColumnWidths(new int[] { 8, 12 });
final String sql = "SELECT\n" + " row_key, tableName.f.c1\n" + "FROM\n" + " hbase.`[TABLE_NAME]` tableName\n" + "WHERE\n" + " row_key BETWEEN 'a2' AND 'b4'";
runHBaseSQLVerifyCount(sql, 3);
final String[] expectedPlan = { ".*startRow=a2, stopRow=b4\\\\x00, filter=FilterList AND.*GREATER_OR_EQUAL, a2.*LESS_OR_EQUAL, b4.*" };
final String[] excludedPlan = {};
final String sqlHBase = canonizeHBaseSQL(sql);
PlanTestBase.testPlanMatchingPatterns(sqlHBase, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushdownLongEqual() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " zip = 85260";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(zip = \\{\"\\$numberLong\":85260\\}\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownOnSubField1() throws Exception {
setColumnWidths(new int[] { 25, 120, 20 });
final String sql = "SELECT\n" + " _id, name, b.attributes.Ambience.touristy attributes\n" + "FROM\n" + " hbase.`business` b\n" + "WHERE\n" + " b.`attributes.Ambience.casual` = false";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(attributes.Ambience.casual = false\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownSubField7() throws Exception {
setColumnWidths(new int[] { 25, 40, 25, 45 });
final String sql = "SELECT\n" + " _id, name, start_date, last_update\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`start_date` = DATE '2012-07-14'";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(start_date = \\{\"\\$dateDay\":\"2012-07-14\"\\}\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownLong() throws Exception {
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " stars > 4.0";
runSQLAndVerifyCount(sql, 2);
final String[] expectedPlan = { "condition=\\(stars > 4\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushdownStringNotEqual() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " name <> 'Sprint'";
runSQLAndVerifyCount(sql, 9);
final String[] expectedPlan = { "condition=\\(name != \"Sprint\"\\)", "columns=\\[`name`, `_id`, `categories`, `full_address`\\]" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushdownDisabled() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " table(hbase.`business`(type => 'maprdb', enablePushdown => false)) business\n" + "WHERE\n" + " name <> 'Sprint'";
runSQLAndVerifyCount(sql, 9);
final String[] expectedPlan = { "condition=null", "columns=\\[`\\*`\\]" };
final String[] excludedPlan = { "condition=\\(name != \"Sprint\"\\)", "columns=\\[`name`, `_id`, `categories`, `full_address`\\]" };
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownIsNull() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, attributes\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`attributes.Ambience.casual` IS NULL";
runSQLAndVerifyCount(sql, 7);
final String[] expectedPlan = { "condition=\\(attributes.Ambience.casual = null\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownSubField4() throws Exception {
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`attributes.Good For.lunch` = true AND" + " stars > 4.1";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(\\(attributes.Good For.lunch = true\\) and \\(stars > 4.1\\)\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownIsNotNull() throws Exception {
setColumnWidths(new int[] { 25, 75, 75, 50 });
final String sql = "SELECT\n" + " _id, name, b.attributes.Parking\n" + "FROM\n" + " hbase.`business` b\n" + "WHERE\n" + " b.`attributes.Ambience.casual` IS NOT NULL";
runSQLAndVerifyCount(sql, 3);
final String[] expectedPlan = { "condition=\\(attributes.Ambience.casual != null\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushdownStringLike() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " name LIKE 'S%'";
runSQLAndVerifyCount(sql, 3);
final String[] expectedPlan = { "condition=\\(name MATCHES \"\\^\\\\\\\\QS\\\\\\\\E\\.\\*\\$\"\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownSubField8() throws Exception {
setColumnWidths(new int[] { 25, 40, 25, 45 });
final String sql = "SELECT\n" + " _id, name, start_date, last_update\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`last_update` = TIMESTAMP '2012-10-20 07:42:46'";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=null" };
final String[] excludedPlan = { "condition=\\(last_update = \\{\"\\$date\":\"2012-10-20T07:42:46.000Z\"\\}\\)" };
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownSubField5() throws Exception {
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`hours.Tuesday.open` < TIME '10:30:00'";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(hours.Tuesday.open < \\{\"\\$time\":\"10:30:00\"\\}\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownSubField6() throws Exception {
final String sql = "SELECT\n" + " *\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " business.`hours.Sunday.close` > TIME '20:30:00'";
runSQLAndVerifyCount(sql, 3);
final String[] expectedPlan = { "condition=\\(hours.Sunday.close > \\{\"\\$time\":\"20:30:00\"\\}\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPruneScanRangeAndPushDownCondition() throws Exception {
// XXX/TODO:
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " _id = 'jFTZmywe7StuZ2hEjxyA' AND\n" + " name = 'Subway'";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(\\(_id = \"jFTZmywe7StuZ2hEjxyA\"\\) and \\(name = \"Subway\"\\)\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownOnSubField2() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, b.attributes.Attire attributes\n" + "FROM\n" + " hbase.`business` b\n" + "WHERE\n" + " b.`attributes.Attire` = 'casual'";
runSQLAndVerifyCount(sql, 4);
final String[] expectedPlan = { "condition=\\(attributes.Attire = \"casual\"\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushDownOnSubField3() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, b.attributes.`Accepts Credit Cards` attributes\n" + "FROM\n" + " hbase.`business` b\n" + "WHERE\n" + " b.`attributes.Accepts Credit Cards` IS NULL";
runSQLAndVerifyCount(sql, 3);
final String[] expectedPlan = { "condition=\\(attributes.Accepts Credit Cards = null\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPruneScanRange() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " _id = 'jFTZmywe7StuZ2hEjxyA'";
runSQLAndVerifyCount(sql, 1);
final String[] expectedPlan = { "condition=\\(_id = \"jFTZmywe7StuZ2hEjxyA\"\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testPushdownStringEqual() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, business.hours.Monday.`open`, categories[1], years[2], full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " name = 'Sprint'";
final Doreplacedent queryResult = MapRDB.newDoreplacedent();
SingleRowListener listener = new SingleRowListener() {
@Override
protected void rowArrived(QueryDataBatch result) {
try {
final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
loader.load(result.getHeader().getDef(), result.getData());
StringBuilder sb = new StringBuilder();
VectorUtil.appendVectorAccessibleContent(loader, sb, "|", false);
loader.clear();
queryResult.set("result", sb.toString());
} catch (SchemaChangeException e) {
queryResult.set("error", "true");
}
}
};
testWithListener(QueryType.SQL, sql, listener);
listener.waitForCompletion();
replacedertNull(queryResult.getString("error"));
replacedertNotNull(queryResult.getString("result"));
String[] fields = queryResult.getString("result").split("\\|");
replacedertEquals("1970-01-01T11:00:00.000", fields[2]);
replacedertEquals("Mobile Phones", fields[3]);
replacedertEquals("2016.0", fields[4]);
final String[] expectedPlan = { "condition=\\(name = \"Sprint\"\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
19
Source : TestSimpleJson.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Test
public void testCompositePredicate() throws Exception {
setColumnWidths(new int[] { 25, 40, 40, 40 });
final String sql = "SELECT\n" + " _id, name, categories, full_address\n" + "FROM\n" + " hbase.`business` business\n" + "WHERE\n" + " zip = 85260\n" + " OR\n" + " city = 'Las Vegas'";
runSQLAndVerifyCount(sql, 4);
final String[] expectedPlan = { "condition=\\(\\(zip = \\{\"\\$numberLong\":85260\\}\\) or \\(city = \"Las Vegas\"\\)\\)" };
final String[] excludedPlan = {};
PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
18
Source : TestWindowFunctions.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
// DRILL-3292
@Test
public void testWindowConstants() throws Exception {
String query = "select rank() over w fn, sum(2) over w sumINTEGER, sum(employee_id) over w sumEmpId, sum(0.5) over w sumFLOAT \n" + "from cp.`employee.json` \n" + "where position_id = 2 \n" + "window w as(parreplacedion by position_id order by employee_id)";
// Validate the plan
final String[] expectedPlan = { "Window.*parreplacedion \\{0\\} order by \\[1\\].*RANK\\(\\), \\$SUM0\\(\\$2\\), SUM\\(\\$1\\), \\$SUM0\\(\\$3\\)", "Scan.*columns=\\[`position_id`, `employee_id`\\]" };
final String[] excludedPatterns = { "Scan.*columns=\\[`\\*`\\]" };
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
testBuilder().sqlQuery(query).ordered().baselineColumns("fn", "sumINTEGER", "sumEmpId", "sumFLOAT").baselineValues(1l, 2l, 2l, 0.5).baselineValues(2l, 4l, 6l, 1.0).baselineValues(3l, 6l, 11l, 1.5).baselineValues(4l, 8l, 31l, 2.0).baselineValues(5l, 10l, 52l, 2.5).baselineValues(6l, 12l, 74l, 3.0).build().run();
}
See More Examples