Skip to content

Instantly share code, notes, and snippets.

@posulliv
Created October 22, 2020 20:16
Show Gist options
  • Save posulliv/44efb42c011babb951e3f25a21a925bf to your computer and use it in GitHub Desktop.
Save posulliv/44efb42c011babb951e3f25a21a925bf to your computer and use it in GitHub Desktop.
@Test
public void testPredicatePushdownWithDate()
{
String tableName = "predicate_test";
tester().getQueryRunner().execute(format("CREATE TABLE %s (a, b) AS SELECT DATE '2020-10-20', 6", tableName));
PushPredicateIntoTableScan pushPredicateIntoTableScan = new PushPredicateIntoTableScan(
tester().getMetadata(),
new TypeOperators(),
tester().getTypeAnalyzer());
MongoTableHandle mongoTable = new MongoTableHandle(new SchemaTableName(SCHEMA_NAME, tableName));
TableHandle table = new TableHandle(
new CatalogName(MONGO_CATALOG_NAME),
mongoTable,
new MongoTransactionHandle(),
Optional.empty());
MongoColumnHandle column = new MongoColumnHandle("a", DATE, false);
long dateValue = TimeUnit.MILLISECONDS.toDays(new DateTime(2020, 10, 20, 0, 0, 0, 0, DateTimeZone.UTC).getMillis());
tester().assertThat(pushPredicateIntoTableScan)
.on(p ->
p.filter(
PlanBuilder.expression("a = DATE '2020-10-20'"),
p.tableScan(
table,
ImmutableList.of(p.symbol("a", DATE)),
ImmutableMap.of(p.symbol("a", DATE), column))))
.matches(filter(
"a = DATE '2020-10-20'",
tableScan(
tableHandle -> ((MongoTableHandle) tableHandle).getConstraint().getDomains().get()
.equals(ImmutableMap.of(column, Domain.singleValue(DATE, dateValue))),
TupleDomain.all(),
ImmutableMap.of("a", equalTo(column)))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment