Search in sources :

Example 6 with EvaluatingNormalizer

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

the class DeleteAnalyzer method analyze.

public AnalyzedDeleteStatement analyze(Delete delete, ParamTypeHints typeHints, CoordinatorTxnCtx txnContext) {
    StatementAnalysisContext stmtCtx = new StatementAnalysisContext(typeHints, Operation.DELETE, txnContext);
    final RelationAnalysisContext relationCtx = stmtCtx.startRelation();
    AnalyzedRelation relation = relationAnalyzer.analyze(delete.getRelation(), stmtCtx);
    stmtCtx.endRelation();
    MaybeAliasedStatement maybeAliasedStatement = MaybeAliasedStatement.analyze(relation);
    relation = maybeAliasedStatement.nonAliasedRelation();
    if (!(relation instanceof DocTableRelation)) {
        throw new UnsupportedOperationException("Cannot delete from relations other than base tables");
    }
    DocTableRelation table = (DocTableRelation) relation;
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, table);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(txnContext, nodeCtx, typeHints, new FullQualifiedNameFieldProvider(relationCtx.sources(), relationCtx.parentSources(), txnContext.sessionContext().searchPath().currentSchema()), new SubqueryAnalyzer(relationAnalyzer, new StatementAnalysisContext(typeHints, Operation.READ, txnContext)));
    Symbol query = Objects.requireNonNullElse(expressionAnalyzer.generateQuerySymbol(delete.getWhere(), new ExpressionAnalysisContext(txnContext.sessionContext())), Literal.BOOLEAN_TRUE);
    query = maybeAliasedStatement.maybeMapFields(query);
    Symbol normalizedQuery = normalizer.normalize(query, txnContext);
    return new AnalyzedDeleteStatement(table, normalizedQuery);
}
Also used : RelationAnalysisContext(io.crate.analyze.relations.RelationAnalysisContext) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) StatementAnalysisContext(io.crate.analyze.relations.StatementAnalysisContext) DocTableRelation(io.crate.analyze.relations.DocTableRelation) SubqueryAnalyzer(io.crate.analyze.expressions.SubqueryAnalyzer) FullQualifiedNameFieldProvider(io.crate.analyze.relations.FullQualifiedNameFieldProvider)

Example 7 with EvaluatingNormalizer

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

the class NullEliminatorTest method assertReplacedAndNormalized.

private void assertReplacedAndNormalized(String expression, String expectedString) {
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(sqlExpressions.nodeCtx);
    assertReplaced(expression, expectedString, s -> normalizer.normalize(s, CoordinatorTxnCtx.systemTransactionContext()));
}
Also used : EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer)

Example 8 with EvaluatingNormalizer

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

the class ProjectorsTest method prepare.

@Before
public void prepare() throws Exception {
    nodeCtx = createNodeContext();
    memoryManager = new OnHeapMemoryManager(bytes -> {
    });
    projectorFactory = new ProjectionToProjectorVisitor(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoneCircuitBreakerService(), nodeCtx, THREAD_POOL, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS), new InputFactory(nodeCtx), new EvaluatingNormalizer(nodeCtx, RowGranularity.SHARD, r -> Literal.ofUnchecked(r.valueType(), r.valueType().sanitizeValue("1")), null), t -> null, t -> null, Version.CURRENT, new ShardId("dummy", UUID.randomUUID().toString(), 0), null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) InputColumn(io.crate.expression.symbol.InputColumn) Arrays(java.util.Arrays) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) NodeLimits(io.crate.execution.jobs.NodeLimits) ArrayList(java.util.ArrayList) Settings(org.elasticsearch.common.settings.Settings) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) Before(org.junit.Before) NodeContext(io.crate.metadata.NodeContext) Answers(org.mockito.Answers) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) Test(org.junit.Test) UUID(java.util.UUID) RamAccounting(io.crate.breaker.RamAccounting) TransportActionProvider(io.crate.execution.TransportActionProvider) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RowGranularity(io.crate.metadata.RowGranularity) Version(org.elasticsearch.Version) Literal(io.crate.expression.symbol.Literal) AggregateMode(io.crate.expression.symbol.AggregateMode) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) Matchers.is(org.hamcrest.Matchers.is) InputFactory(io.crate.expression.InputFactory) Collections(java.util.Collections) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Mockito.mock(org.mockito.Mockito.mock) ShardId(org.elasticsearch.index.shard.ShardId) InputFactory(io.crate.expression.InputFactory) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NodeLimits(io.crate.execution.jobs.NodeLimits) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 9 with EvaluatingNormalizer

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

the class WhereClauseOptimizerTest method optimize.

private WhereClauseOptimizer.DetailedQuery optimize(String statement) {
    QueriedSelectRelation queriedTable = e.analyze(statement);
    DocTableRelation table = ((DocTableRelation) queriedTable.from().get(0));
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(e.nodeCtx, RowGranularity.CLUSTER, null, table);
    return WhereClauseOptimizer.optimize(normalizer, queriedTable.where(), table.tableInfo(), e.getPlannerContext(clusterService.state()).transactionContext(), e.nodeCtx);
}
Also used : EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) QueriedSelectRelation(io.crate.analyze.QueriedSelectRelation) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Example 10 with EvaluatingNormalizer

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

the class RoutedCollectPhaseTest method testNormalizeNoop.

@Test
public void testNormalizeNoop() throws Exception {
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(Literal.of(10)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect, sameInstance(collect));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) 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