use of io.crate.exceptions.UnsupportedFeatureException in project crate by crate.
the class LuceneReferenceResolver method getImplementation.
@Override
public LuceneCollectorExpression<?> getImplementation(Reference refInfo) {
assert refInfo.granularity() == RowGranularity.DOC : "lucene collector expressions are required to be on DOC granularity";
ColumnIdent columnIdent = refInfo.ident().columnIdent();
String name = columnIdent.name();
if (RawCollectorExpression.COLUMN_NAME.equals(name)) {
if (columnIdent.isColumn()) {
return new RawCollectorExpression();
} else {
// TODO: implement an Object source expression which may support subscripts
throw new UnsupportedFeatureException(String.format(Locale.ENGLISH, "_source expression does not support subscripts %s", columnIdent.fqn()));
}
} else if (UidCollectorExpression.COLUMN_NAME.equals(name)) {
return new UidCollectorExpression();
} else if (IdCollectorExpression.COLUMN_NAME.equals(name)) {
return new IdCollectorExpression();
} else if (DocCollectorExpression.COLUMN_NAME.equals(name)) {
return DocCollectorExpression.create(refInfo);
} else if (FetchIdCollectorExpression.COLUMN_NAME.equals(name)) {
return new FetchIdCollectorExpression();
} else if (ScoreCollectorExpression.COLUMN_NAME.equals(name)) {
return new ScoreCollectorExpression();
}
String colName = columnIdent.fqn();
MappedFieldType fieldType = fieldTypeLookup.get(colName);
if (fieldType == null) {
return new NullValueCollectorExpression(colName);
}
switch(refInfo.valueType().id()) {
case ByteType.ID:
return new ByteColumnReference(colName);
case ShortType.ID:
return new ShortColumnReference(colName);
case IpType.ID:
return new IpColumnReference(colName);
case StringType.ID:
return new BytesRefColumnReference(colName, fieldType);
case DoubleType.ID:
return new DoubleColumnReference(colName, fieldType);
case BooleanType.ID:
return new BooleanColumnReference(colName);
case ObjectType.ID:
return new ObjectColumnReference(colName);
case FloatType.ID:
return new FloatColumnReference(colName, fieldType);
case LongType.ID:
case TimestampType.ID:
return new LongColumnReference(colName);
case IntegerType.ID:
return new IntegerColumnReference(colName);
case GeoPointType.ID:
return new GeoPointColumnReference(colName, fieldType);
case GeoShapeType.ID:
return new GeoShapeColumnReference(colName);
case ArrayType.ID:
case SetType.ID:
return DocCollectorExpression.create(DocReferenceConverter.toSourceLookup(refInfo));
default:
throw new UnhandledServerException(String.format(Locale.ENGLISH, "unsupported type '%s'", refInfo.valueType().getName()));
}
}
use of io.crate.exceptions.UnsupportedFeatureException 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.exceptions.UnsupportedFeatureException in project crate by crate.
the class CopyAnalyzer method convertCopyTo.
CopyToAnalyzedStatement convertCopyTo(CopyTo node, Analysis analysis) {
if (!node.directoryUri()) {
throw new UnsupportedOperationException("Using COPY TO without specifying a DIRECTORY is not supported");
}
TableInfo tableInfo = schemas.getTableInfo(TableIdent.of(node.table(), analysis.sessionContext().defaultSchema()));
if (!(tableInfo instanceof DocTableInfo)) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "Cannot COPY %s TO. COPY TO only supports user tables", tableInfo.ident()));
}
Operation.blockedRaiseException(tableInfo, Operation.READ);
DocTableRelation tableRelation = new DocTableRelation((DocTableInfo) tableInfo);
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, tableRelation);
ExpressionAnalyzer expressionAnalyzer = createExpressionAnalyzer(analysis, tableRelation);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
Settings settings = GenericPropertiesConverter.settingsFromProperties(node.genericProperties(), analysis.parameterContext(), SETTINGS_APPLIERS).build();
WriterProjection.CompressionType compressionType = settingAsEnum(WriterProjection.CompressionType.class, settings.get(COMPRESSION_SETTINGS.name()));
WriterProjection.OutputFormat outputFormat = settingAsEnum(WriterProjection.OutputFormat.class, settings.get(OUTPUT_FORMAT_SETTINGS.name()));
Symbol uri = expressionAnalyzer.convert(node.targetUri(), expressionAnalysisContext);
uri = normalizer.normalize(uri, analysis.transactionContext());
List<String> partitions = resolvePartitions(node, analysis, tableRelation);
List<Symbol> outputs = new ArrayList<>();
QuerySpec querySpec = new QuerySpec();
WhereClause whereClause = createWhereClause(node.whereClause(), tableRelation, partitions, normalizer, expressionAnalyzer, expressionAnalysisContext, analysis.transactionContext());
querySpec.where(whereClause);
Map<ColumnIdent, Symbol> overwrites = null;
boolean columnsDefined = false;
List<String> outputNames = null;
if (!node.columns().isEmpty()) {
outputNames = new ArrayList<>(node.columns().size());
for (Expression expression : node.columns()) {
Symbol symbol = expressionAnalyzer.convert(expression, expressionAnalysisContext);
symbol = normalizer.normalize(symbol, analysis.transactionContext());
outputNames.add(SymbolPrinter.INSTANCE.printSimple(symbol));
outputs.add(DocReferenceConverter.convertIf(symbol));
}
columnsDefined = true;
} else {
Reference sourceRef;
if (tableRelation.tableInfo().isPartitioned() && partitions.isEmpty()) {
// table is partitioned, insert partitioned columns into the output
overwrites = new HashMap<>();
for (Reference reference : tableRelation.tableInfo().partitionedByColumns()) {
if (!(reference instanceof GeneratedReference)) {
overwrites.put(reference.ident().columnIdent(), reference);
}
}
if (overwrites.size() > 0) {
sourceRef = tableRelation.tableInfo().getReference(DocSysColumns.DOC);
} else {
sourceRef = tableRelation.tableInfo().getReference(DocSysColumns.RAW);
}
} else {
sourceRef = tableRelation.tableInfo().getReference(DocSysColumns.RAW);
}
outputs = ImmutableList.<Symbol>of(sourceRef);
}
querySpec.outputs(outputs);
if (!columnsDefined && outputFormat == WriterProjection.OutputFormat.JSON_ARRAY) {
throw new UnsupportedFeatureException("Output format not supported without specifying columns.");
}
QueriedDocTable subRelation = new QueriedDocTable(tableRelation, querySpec);
return new CopyToAnalyzedStatement(subRelation, settings, uri, compressionType, outputFormat, outputNames, columnsDefined, overwrites);
}
use of io.crate.exceptions.UnsupportedFeatureException in project crate by crate.
the class RelationAnalyzer method visitTableFunction.
@Override
public AnalyzedRelation visitTableFunction(TableFunction node, StatementAnalysisContext statementContext) {
RelationAnalysisContext context = statementContext.currentRelationContext();
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, statementContext.sessionContext(), statementContext.convertParamFunction(), new FieldProvider() {
@Override
public Symbol resolveField(QualifiedName qualifiedName, Operation operation) {
throw new UnsupportedOperationException("Can only resolve literals");
}
@Override
public Symbol resolveField(QualifiedName qualifiedName, @Nullable List path, Operation operation) {
throw new UnsupportedOperationException("Can only resolve literals");
}
}, null);
Function function = (Function) expressionAnalyzer.convert(node.functionCall(), context.expressionAnalysisContext());
FunctionImplementation functionImplementation = functions.getSafe(function.info().ident());
if (functionImplementation.info().type() != FunctionInfo.Type.TABLE) {
throw new UnsupportedFeatureException("Non table function " + function.info().ident().name() + " is not supported in from clause");
}
TableFunctionImplementation tableFunction = (TableFunctionImplementation) functionImplementation;
TableInfo tableInfo = tableFunction.createTableInfo(clusterService);
Operation.blockedRaiseException(tableInfo, statementContext.currentOperation());
TableRelation tableRelation = new TableFunctionRelation(tableInfo, tableFunction, function);
context.addSourceRelation(node.name(), tableRelation);
return tableRelation;
}
Aggregations