Tests for the org.apache.calcite.adapter.pig package.
| 35 | * Tests for the {@code org.apache.calcite.adapter.pig} package. |
| 36 | */ |
| 37 | class PigAdapterTest extends AbstractPigTest { |
| 38 | |
| 39 | // Undo the %20 replacement of a space by URL |
| 40 | public static final ImmutableMap<String, String> MODEL = |
| 41 | ImmutableMap.of("model", |
| 42 | Sources.of(PigAdapterTest.class.getResource("/model.json")) |
| 43 | .file().getAbsolutePath()); |
| 44 | |
| 45 | @Test void testScanAndFilter() { |
| 46 | CalciteAssert.that() |
| 47 | .with(MODEL) |
| 48 | .query("select * from \"t\" where \"tc0\" > 'abc'") |
| 49 | .explainContains("PigToEnumerableConverter\n" |
| 50 | + " PigFilter(condition=[>($0, 'abc')])\n" |
| 51 | + " PigTableScan(table=[[PIG, t]])") |
| 52 | .runs() |
| 53 | .queryContains( |
| 54 | pigScriptChecker("t = LOAD '" |
| 55 | + getFullPathForTestDataFile("data.txt") |
| 56 | + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" |
| 57 | + "t = FILTER t BY (tc0 > 'abc');")); |
| 58 | } |
| 59 | |
| 60 | @Test void testImplWithMultipleFilters() { |
| 61 | CalciteAssert.that() |
| 62 | .with(MODEL) |
| 63 | .query("select * from \"t\" where \"tc0\" > 'abc' and \"tc1\" = '3'") |
| 64 | .explainContains("PigToEnumerableConverter\n" |
| 65 | + " PigFilter(condition=[AND(>($0, 'abc'), =($1, '3'))])\n" |
| 66 | + " PigTableScan(table=[[PIG, t]])") |
| 67 | .runs() |
| 68 | .queryContains( |
| 69 | pigScriptChecker("t = LOAD '" |
| 70 | + getFullPathForTestDataFile("data.txt") |
| 71 | + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" |
| 72 | + "t = FILTER t BY (tc0 > 'abc') AND (tc1 == '3');")); |
| 73 | } |
| 74 | |
| 75 | @Test void testImplWithGroupByAndCount() { |
| 76 | CalciteAssert.that() |
| 77 | .with(MODEL) |
| 78 | .query("select count(\"tc1\") c from \"t\" group by \"tc0\"") |
| 79 | .explainContains("PigToEnumerableConverter\n" |
| 80 | + " PigAggregate(group=[{0}], C=[COUNT($1)])\n" |
| 81 | + " PigTableScan(table=[[PIG, t]])") |
| 82 | .runs() |
| 83 | .queryContains( |
| 84 | pigScriptChecker("t = LOAD '" |
| 85 | + getFullPathForTestDataFile("data.txt") |
| 86 | + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" |
| 87 | + "t = GROUP t BY (tc0);\n" |
| 88 | + "t = FOREACH t {\n" |
| 89 | + " GENERATE group AS tc0, COUNT(t.tc1) AS C;\n" |
| 90 | + "};")); |
| 91 | } |
| 92 | |
| 93 | @Test void testImplWithCountWithoutGroupBy() { |
| 94 | CalciteAssert.that() |
nothing calls this directly
no test coverage detected