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));
}
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;
}
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));
}
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));
}
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));
}
Aggregations