Search in sources :

Example 11 with EvaluatingNormalizer

use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.

the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.

@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.orderBy(new OrderBy(Collections.singletonList(toInt10)));
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.orderBy(), notNullValue());
}
Also used : OrderBy(io.crate.analyze.OrderBy) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 12 with EvaluatingNormalizer

use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.

the class RoutedCollectPhaseTest method testNormalizePreservesNodePageSizeHint.

@Test
public void testNormalizePreservesNodePageSizeHint() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.nodePageSizeHint(10);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.nodePageSizeHint(), is(10));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 13 with EvaluatingNormalizer

use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.

the class EvaluatingNormalizerTest method testEvaluationClusterGranularity.

@Test
public void testEvaluationClusterGranularity() {
    EvaluatingNormalizer visitor = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, referenceResolver, null);
    Function op_or = prepareFunctionTree();
    Symbol query = visitor.normalize(op_or, coordinatorTxnCtx);
    assertThat(query, instanceOf(Function.class));
}
Also used : Function(io.crate.expression.symbol.Function) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Example 14 with EvaluatingNormalizer

use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.

the class EvaluatingNormalizerTest method testEvaluation.

@Test
public void testEvaluation() {
    EvaluatingNormalizer visitor = new EvaluatingNormalizer(nodeCtx, RowGranularity.NODE, referenceResolver, null);
    Function op_or = prepareFunctionTree();
    // the dummy reference load == 0.08 evaluates to true,
    // so the whole query can be normalized to a single boolean literal
    Symbol query = visitor.normalize(op_or, coordinatorTxnCtx);
    assertThat(query, isLiteral(true));
}
Also used : Function(io.crate.expression.symbol.Function) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Example 15 with EvaluatingNormalizer

use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.

the class SelectStatementAnalyzerTest method test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes.

@Test
public void test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable("create table test (shape GEO_SHAPE)").build();
    String stmt = "SELECT * FROM test WHERE MATCH (shape, 'POINT(1.2 1.3)')";
    QueriedSelectRelation rel = executor.analyze(stmt);
    Symbol where = rel.where();
    assertThat(where, instanceOf(MatchPredicate.class));
    DocTableInfo table = executor.resolveTableInfo("test");
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(executor.nodeCtx, RowGranularity.DOC, null, new DocTableRelation(table));
    Symbol normalized = normalizer.normalize(where, CoordinatorTxnCtx.systemTransactionContext());
    assertThat(normalized, isFunction("match"));
    Function match = (Function) normalized;
    assertThat(match.arguments().get(1).valueType(), is(DataTypes.GEO_SHAPE));
    assertThat(match.info().ident().argumentTypes().get(1), is(DataTypes.GEO_SHAPE));
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(Version.V_4_1_8);
    match.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(Version.V_4_1_8);
    Function serializedTo41 = new Function(in);
    assertThat(serializedTo41.info().ident().argumentTypes().get(1), is(DataTypes.STRING));
}
Also used : DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) DocTableInfo(io.crate.metadata.doc.DocTableInfo) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) DocTableRelation(io.crate.analyze.relations.DocTableRelation) BitString(io.crate.sql.tree.BitString) MatchPredicate(io.crate.expression.symbol.MatchPredicate) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)24 Symbol (io.crate.expression.symbol.Symbol)16 DocTableRelation (io.crate.analyze.relations.DocTableRelation)9 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)8 Test (org.junit.Test)7 RowGranularity (io.crate.metadata.RowGranularity)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 WhereClause (io.crate.analyze.WhereClause)5 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)5 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)5 Literal (io.crate.expression.symbol.Literal)5 NodeContext (io.crate.metadata.NodeContext)5 Routing (io.crate.metadata.Routing)5 ArrayList (java.util.ArrayList)5 Lists2 (io.crate.common.collections.Lists2)4 Nullable (javax.annotation.Nullable)4 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)3 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 FullQualifiedNameFieldProvider (io.crate.analyze.relations.FullQualifiedNameFieldProvider)3 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)3