Search in sources :

Example 1 with UnsupportedFeatureException

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()));
    }
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) ColumnIdent(io.crate.metadata.ColumnIdent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) UnhandledServerException(io.crate.exceptions.UnhandledServerException)

Example 2 with UnsupportedFeatureException

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();
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Symbol(io.crate.analyze.symbol.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) Settings(org.elasticsearch.common.settings.Settings)

Example 3 with UnsupportedFeatureException

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Settings(org.elasticsearch.common.settings.Settings) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) WriterProjection(io.crate.planner.projection.WriterProjection) QueriedDocTable(io.crate.analyze.relations.QueriedDocTable) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Example 4 with UnsupportedFeatureException

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;
}
Also used : TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) Operation(io.crate.metadata.table.Operation) Function(io.crate.analyze.symbol.Function) ImmutableList(com.google.common.collect.ImmutableList) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo)

Aggregations

UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)4 Symbol (io.crate.analyze.symbol.Symbol)3 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 TableInfo (io.crate.metadata.table.TableInfo)2 Settings (org.elasticsearch.common.settings.Settings)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)1 Function (io.crate.analyze.symbol.Function)1 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 SysClusterTableInfo (io.crate.metadata.sys.SysClusterTableInfo)1 Operation (io.crate.metadata.table.Operation)1 TableFunctionImplementation (io.crate.metadata.tablefunctions.TableFunctionImplementation)1 WriterProjection (io.crate.planner.projection.WriterProjection)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1