use of io.crate.metadata.RelationName in project crate by crate.
the class WhereClauseAnalyzerTest method testGenColRoundingFunctionNoSwappingOperatorOptimization.
@Test
public void testGenColRoundingFunctionNoSwappingOperatorOptimization() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts >= '2015-01-02T12:00:00'");
assertThat(whereClause.partitions().size(), is(1));
assertThat(whereClause.partitions().get(0), is(new PartitionName(new RelationName("doc", "generated_col"), Arrays.asList("1420156800000", "-2")).asIndexName()));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectFromPartitionedTable.
@Test
public void testSelectFromPartitionedTable() throws Exception {
String partition1 = new PartitionName(new RelationName("doc", "parted"), Arrays.asList("1395874800000")).asIndexName();
String partition2 = new PartitionName(new RelationName("doc", "parted"), Arrays.asList("1395961200000")).asIndexName();
String partition3 = new PartitionName(new RelationName("doc", "parted"), singletonList(null)).asIndexName();
WhereClause whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000");
assertEquals(List.of(partition1), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 " + "and substr(name, 0, 4) = 'this'");
assertEquals(List.of(partition1), whereClause.partitions());
assertThat(whereClause.hasQuery(), is(true));
whereClause = analyzeSelectWhere("select id, name from parted where date >= 1395874800000");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date < 1395874800000");
assertEquals(List.of(), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isLiteral(false));
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 and date = 1395961200000");
assertEquals(List.of(), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isLiteral(false));
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 or date = 1395961200000");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date < 1395874800000 or date > 1395874800000");
assertEquals(List.of(partition2), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000, 1395961200000)");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000, 1395961200000) and id = 1");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isFunction("op_="));
/**
* obj['col'] = 'undefined' => null as col doesn't exist
*
* partition1: not (true and null) -> not (null) -> null -> no match
* partition2: not (false and null) -> not (false) -> true -> match
* partition3: not (null and null) -> not (null) -> null -> no match
*/
whereClause = analyzeSelectWhere("select id, name from parted where not (date = 1395874800000 and obj['col'] = 'undefined')");
assertThat(whereClause.partitions(), containsInAnyOrder(partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000) or date in (1395961200000)");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395961200000 and id = 1");
assertEquals(List.of(partition2), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isFunction("op_="));
whereClause = analyzeSelectWhere("select id, name from parted where (date =1395874800000 or date = 1395961200000) and id = 1");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isFunction("op_="));
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 and id is null");
assertEquals(List.of(partition1), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isFunction("op_isnull"));
whereClause = analyzeSelectWhere("select id, name from parted where date is null and id = 1");
assertEquals(List.of(partition3), whereClause.partitions());
assertThat(whereClause.queryOrFallback(), isFunction("op_="));
whereClause = analyzeSelectWhere("select id, name from parted where 1395874700000 < date and date < 1395961200001");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
whereClause = analyzeSelectWhere("select id, name from parted where '2014-03-16T22:58:20' < date and date < '2014-03-27T23:00:01'");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertThat(whereClause.queryOrFallback(), isLiteral(true));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class ExpressionAnalyzerTest method testAnalyzeArraySliceFunctionCall.
@Test
public void testAnalyzeArraySliceFunctionCall() {
ReferenceIdent arrayRefIdent = new ReferenceIdent(new RelationName("doc", "tarr"), "xs");
Reference arrayRef = new Reference(arrayRefIdent, RowGranularity.DOC, DataTypes.INTEGER_ARRAY, ColumnPolicy.DYNAMIC, Reference.IndexType.PLAIN, true, true, 1, null);
CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
ExpressionAnalysisContext localContext = new ExpressionAnalysisContext(txnCtx.sessionContext());
Symbol function = ExpressionAnalyzer.allocateFunction(ArraySliceFunction.NAME, List.of(arrayRef, Literal.of(1), Literal.of(3)), null, localContext, txnCtx, expressions.nodeCtx);
var result = executor.asSymbol("tarr.xs[1:3]");
assertThat(result, is(equalTo(function)));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.
@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
TableInfo t1 = executor.resolveTableInfo("t1");
TableRelation relation = new TableRelation(t1);
RelationName a1 = new RelationName(null, "a1");
RelationName a2 = new RelationName(null, "a2");
Map<RelationName, AnalyzedRelation> sources = Map.of(a1, new AliasedAnalyzedRelation(relation, a1), a2, new AliasedAnalyzedRelation(relation, a2));
SessionContext sessionContext = SessionContext.systemSessionContext();
CoordinatorTxnCtx coordinatorTxnCtx = new CoordinatorTxnCtx(sessionContext);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, expressions.nodeCtx, paramTypeHints, new FullQualifiedNameFieldProvider(sources, ParentRelations.NO_PARENTS, sessionContext.searchPath().currentSchema()), null);
Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not a1.x = 1 and not a2.x = 1"), context);
ScopedSymbol t1Id = ((ScopedSymbol) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
ScopedSymbol t2Id = ((ScopedSymbol) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
assertThat(t1Id.relation(), is(not(t2Id.relation())));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class SubSelectAnalyzerTest method testSubSelectWithNestedAlias.
@Test
public void testSubSelectWithNestedAlias() throws Exception {
QueriedSelectRelation relation = analyze("select tt.aa, (tt.xi + 1::int)" + " from (select (x + i) as xi, concat(a, a) as aa, i from t1) as tt");
assertThat(relation.outputs(), contains(isField("aa"), isFunction("add", isField("xi"), isLiteral(1))));
QueriedSelectRelation innerQSR = (QueriedSelectRelation) ((AliasedAnalyzedRelation) relation.from().get(0)).relation();
assertThat(innerQSR.from(), contains(isDocTable(new RelationName("doc", "t1"))));
}
Aggregations