Search in sources :

Example 6 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class RandomFunctionTest method normalizeReference.

@Test
public void normalizeReference() {
    Function function = new Function(random.info(), Collections.<Symbol>emptyList());
    Function normalized = (Function) random.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized, sameInstance(function));
}
Also used : Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

Example 7 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class DeleteAnalyzer method analyze.

public AnalyzedStatement analyze(Delete node, Analysis analysis) {
    int numNested = 1;
    Function<ParameterExpression, Symbol> convertParamFunction = analysis.parameterContext();
    StatementAnalysisContext statementAnalysisContext = new StatementAnalysisContext(analysis.sessionContext(), convertParamFunction, Operation.DELETE, analysis.transactionContext());
    RelationAnalysisContext relationAnalysisContext = statementAnalysisContext.startRelation();
    AnalyzedRelation analyzedRelation = relationAnalyzer.analyze(node.getRelation(), statementAnalysisContext);
    assert analyzedRelation instanceof DocTableRelation : "analyzedRelation must be DocTableRelation";
    DocTableRelation docTableRelation = (DocTableRelation) analyzedRelation;
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, docTableRelation);
    DeleteAnalyzedStatement deleteAnalyzedStatement = new DeleteAnalyzedStatement(docTableRelation);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), convertParamFunction, new FullQualifedNameFieldProvider(relationAnalysisContext.sources()), null);
    ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
    WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, deleteAnalyzedStatement.analyzedRelation());
    if (analysis.parameterContext().hasBulkParams()) {
        numNested = analysis.parameterContext().numBulkParams();
    }
    TransactionContext transactionContext = analysis.transactionContext();
    for (int i = 0; i < numNested; i++) {
        analysis.parameterContext().setBulkIdx(i);
        Symbol query = expressionAnalyzer.generateQuerySymbol(node.getWhere(), expressionAnalysisContext);
        WhereClause whereClause = new WhereClause(normalizer.normalize(query, transactionContext));
        whereClause = validate(whereClauseAnalyzer.analyze(whereClause, transactionContext));
        deleteAnalyzedStatement.whereClauses.add(whereClause);
    }
    statementAnalysisContext.endRelation();
    return deleteAnalyzedStatement;
}
Also used : ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) TransactionContext(io.crate.metadata.TransactionContext) ParameterExpression(io.crate.sql.tree.ParameterExpression) WhereClauseAnalyzer(io.crate.analyze.where.WhereClauseAnalyzer)

Example 8 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class AggregationTest method normalize.

protected Symbol normalize(String functionName, Symbol... args) {
    DataType[] argTypes = new DataType[args.length];
    for (int i = 0; i < args.length; i++) {
        argTypes[i] = args[i].valueType();
    }
    AggregationFunction function = (AggregationFunction) functions.get(new FunctionIdent(functionName, Arrays.asList(argTypes)));
    return function.normalizeSymbol(new Function(function.info(), Arrays.asList(args)), new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) FunctionIdent(io.crate.metadata.FunctionIdent) TransactionContext(io.crate.metadata.TransactionContext) DataType(io.crate.types.DataType)

Example 9 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class RegexpMatchCaseInsensitiveOperatorTest method normalizeSymbol.

private static Symbol normalizeSymbol(String source, String pattern) {
    RegexpMatchCaseInsensitiveOperator op = new RegexpMatchCaseInsensitiveOperator();
    Function function = new Function(op.info(), Arrays.<Symbol>asList(Literal.of(source), Literal.of(pattern)));
    return op.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext)

Example 10 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class AnyLikeOperatorTest method normalizeSymbol.

private static Symbol normalizeSymbol(String pattern, String... expressions) {
    Literal patternLiteral = Literal.of(pattern);
    Object[] value = new Object[expressions.length];
    for (int i = 0; i < expressions.length; i++) {
        value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
    }
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
    AnyLikeOperator impl = (AnyLikeOperator) new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(patternLiteral.valueType(), valuesLiteral.valueType()));
    Function function = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    return impl.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

TransactionContext (io.crate.metadata.TransactionContext)10 Function (io.crate.analyze.symbol.Function)8 Literal (io.crate.analyze.symbol.Literal)4 ArrayType (io.crate.types.ArrayType)4 BytesRef (org.apache.lucene.util.BytesRef)4 Test (org.junit.Test)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)3 Symbol (io.crate.analyze.symbol.Symbol)2 Input (io.crate.data.Input)2 FunctionImplementation (io.crate.metadata.FunctionImplementation)2 NotPredicate (io.crate.operation.predicate.NotPredicate)2 EvaluatingNormalizer (io.crate.analyze.EvaluatingNormalizer)1 OrderBy (io.crate.analyze.OrderBy)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 WhereClauseAnalyzer (io.crate.analyze.where.WhereClauseAnalyzer)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 Routing (io.crate.metadata.Routing)1 AbstractScalarFunctionsTest (io.crate.operation.scalar.AbstractScalarFunctionsTest)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1