use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class RelationAnalyzer method rewriteGlobalDistinct.
@Nullable
private List<Symbol> rewriteGlobalDistinct(List<Symbol> outputSymbols) {
List<Symbol> groupBy = new ArrayList<>(outputSymbols.size());
for (Symbol symbol : outputSymbols) {
if (!Aggregations.containsAggregation(symbol)) {
GroupBySymbolValidator.validate(symbol);
groupBy.add(symbol);
}
}
return groupBy;
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class AnalyzedTableElements method processGeneratedExpression.
private void processGeneratedExpression(ExpressionAnalyzer expressionAnalyzer, SymbolPrinter symbolPrinter, AnalyzedColumnDefinition columnDefinition, ExpressionAnalysisContext expressionAnalysisContext) {
// validate expression
Symbol function = expressionAnalyzer.convert(columnDefinition.generatedExpression(), expressionAnalysisContext);
String formattedExpression;
DataType valueType = function.valueType();
DataType definedType = columnDefinition.dataType() == null ? null : DataTypes.ofMappingNameSafe(columnDefinition.dataType());
// check for optional defined type and add `cast` to expression if possible
if (definedType != null && !definedType.equals(valueType)) {
Preconditions.checkArgument(valueType.isConvertableTo(definedType), "generated expression value type '%s' not supported for conversion to '%s'", valueType, definedType.getName());
Symbol castFunction = CastFunctionResolver.generateCastFunction(function, definedType, false);
// no full qualified references here
formattedExpression = symbolPrinter.print(castFunction, SymbolPrinter.Style.PARSEABLE_NOT_QUALIFIED);
} else {
columnDefinition.dataType(function.valueType().getName());
// no full qualified references here
formattedExpression = symbolPrinter.print(function, SymbolPrinter.Style.PARSEABLE_NOT_QUALIFIED);
}
columnDefinition.formattedGeneratedExpression(formattedExpression);
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class CopyAnalyzer method createWhereClause.
private WhereClause createWhereClause(Optional<Expression> where, DocTableRelation tableRelation, List<String> partitions, EvaluatingNormalizer normalizer, ExpressionAnalyzer expressionAnalyzer, ExpressionAnalysisContext expressionAnalysisContext, TransactionContext transactionContext) {
WhereClause whereClause = null;
if (where.isPresent()) {
WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, tableRelation);
Symbol query = expressionAnalyzer.convert(where.get(), expressionAnalysisContext);
whereClause = new WhereClause(normalizer.normalize(query, transactionContext));
whereClause = whereClauseAnalyzer.analyze(whereClause, transactionContext);
}
if (whereClause == null) {
return new WhereClause(null, null, partitions);
} else if (whereClause.noMatch()) {
return whereClause;
} else {
if (!whereClause.partitions().isEmpty() && !partitions.isEmpty() && !whereClause.partitions().equals(partitions)) {
throw new IllegalArgumentException("Given partition ident does not match partition evaluated from where clause");
}
return new WhereClause(whereClause.query(), whereClause.docKeys().orElse(null), partitions.isEmpty() ? whereClause.partitions() : partitions);
}
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class CopyAnalyzer method settingsFromProperties.
private Settings settingsFromProperties(Map<String, Expression> properties, ExpressionAnalyzer expressionAnalyzer, ExpressionAnalysisContext expressionAnalysisContext) {
Settings.Builder builder = Settings.builder();
for (Map.Entry<String, Expression> entry : properties.entrySet()) {
String key = entry.getKey();
Expression expression = entry.getValue();
if (expression instanceof ArrayLiteral) {
throw new IllegalArgumentException("Invalid argument(s) passed to parameter");
}
if (expression instanceof QualifiedNameReference) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Can't use column reference in property assignment \"%s = %s\". Use literals instead.", key, ((QualifiedNameReference) expression).getName().toString()));
}
Symbol v = expressionAnalyzer.convert(expression, expressionAnalysisContext);
if (!v.symbolType().isValueSymbol()) {
throw new UnsupportedFeatureException("Only literals are allowed as parameter values");
}
builder.put(key, ValueSymbolVisitor.STRING.process(v));
}
return builder.build();
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class ReferenceToLiteralConverterTest method testReplaceSubscriptReference.
@Test
public void testReplaceSubscriptReference() throws Exception {
Object[] inputValues = new Object[] { MapBuilder.newMapBuilder().put("name", "Ford").map() };
Reference userRef = new Reference(new ReferenceIdent(TABLE_IDENT, new ColumnIdent("user")), RowGranularity.DOC, DataTypes.OBJECT);
Reference nameRef = new Reference(new ReferenceIdent(TABLE_IDENT, new ColumnIdent("user", ImmutableList.of("name"))), RowGranularity.DOC, DataTypes.STRING);
ReferenceToLiteralConverter.Context context = new ReferenceToLiteralConverter.Context(ImmutableList.of(userRef), ImmutableList.of(nameRef));
context.values(inputValues);
Symbol replacedSymbol = REFERENCE_TO_LITERAL_CONVERTER.process(nameRef, context);
assertThat(replacedSymbol, isLiteral("Ford", DataTypes.STRING));
}
Aggregations