Search in sources :

Example 11 with CQLFragment

use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.

the class SchemaSettings method columnsToVariables.

@NonNull
private Set<CQLWord> columnsToVariables(Collection<ColumnMetadata> columns) {
    Map<CQLWord, CQLFragment> boundVariables = queryInspector.getAssignments();
    Set<CQLWord> variables = new HashSet<>(columns.size());
    for (ColumnMetadata column : columns) {
        CQLFragment variable = boundVariables.get(CQLWord.fromCqlIdentifier(column.getName()));
        if (variable instanceof CQLWord) {
            variables.add((CQLWord) variable);
        }
    }
    return variables;
}
Also used : ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 12 with CQLFragment

use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.

the class SchemaSettings method inferFieldsToVariablesMap.

private ImmutableMultimap<MappingField, CQLFragment> inferFieldsToVariablesMap(Collection<CQLFragment> columns) {
    // use a builder to preserve iteration order
    ImmutableMultimap.Builder<MappingField, CQLFragment> fieldsToVariables = ImmutableMultimap.builder();
    List<CQLFragment> excludedVariables = new ArrayList<>(mapping.getExcludedVariables());
    if (!isCounterTable() && schemaGenerationStrategy.isMapping()) {
        for (CQLWord variable : mapping.getExcludedVariables()) {
            if (preserveTimestamp) {
                excludedVariables.add(new FunctionCall(null, WRITETIME, variable));
            }
            if (preserveTtl) {
                excludedVariables.add(new FunctionCall(null, TTL, variable));
            }
        }
    }
    int i = 0;
    for (CQLFragment colName : columns) {
        if (!excludedVariables.contains(colName)) {
            if (mappingPreference == INDEXED_ONLY) {
                fieldsToVariables.put(new IndexedMappingField(i), colName);
            } else {
                fieldsToVariables.put(new MappedMappingField(colName.render(INTERNAL)), colName);
            }
        }
        i++;
    }
    return fieldsToVariables.build();
}
Also used : MappedMappingField(com.datastax.oss.dsbulk.mapping.MappedMappingField) ArrayList(java.util.ArrayList) IndexedMappingField(com.datastax.oss.dsbulk.mapping.IndexedMappingField) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) ImmutableMultimap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMultimap) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) FunctionCall(com.datastax.oss.dsbulk.mapping.FunctionCall) IndexedMappingField(com.datastax.oss.dsbulk.mapping.IndexedMappingField) MappingField(com.datastax.oss.dsbulk.mapping.MappingField) MappedMappingField(com.datastax.oss.dsbulk.mapping.MappedMappingField)

Example 13 with CQLFragment

use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.

the class QueryInspector method visitNormalInsertStatement.

@Override
public CQLFragment visitNormalInsertStatement(NormalInsertStatementContext ctx) {
    if (ctx.cident().size() != ctx.term().size()) {
        throw new IllegalArgumentException(String.format("Invalid query: the number of columns to insert (%d) does not match the number of terms (%d): %s.", ctx.cident().size(), ctx.term().size(), query));
    }
    for (int i = 0; i < ctx.cident().size(); i++) {
        CQLWord column = visitCident(ctx.cident().get(i));
        CQLFragment variable = visitTerm(ctx.term().get(i));
        assignmentsBuilder.put(column, variable == QUESTION_MARK ? column : variable);
    }
    if (ctx.usingClause() != null) {
        visitUsingClause(ctx.usingClause());
    }
    return null;
}
Also used : CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment)

Example 14 with CQLFragment

use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.

the class QueryInspector method visitRelation.

// WHERE clause
@Override
@Nullable
public CQLFragment visitRelation(RelationContext ctx) {
    // relation contains another relation: drill down
    while (ctx.relation() != null) {
        ctx = ctx.relation();
    }
    // myCol = :myVar or myCol = ?
    if (ctx.getChildCount() == 3 && ctx.getChild(0) instanceof CidentContext && ctx.getChild(1) instanceof RelationTypeContext && ctx.getChild(2) instanceof TermContext && ctx.getChild(1).getText().equals("=")) {
        CQLWord column = visitCident(ctx.cident());
        if (column.equals(SOLR_QUERY)) {
            hasSearchClause = true;
        }
        CQLFragment variable = visitTerm(ctx.term().get(0));
        assignmentsBuilder.put(column, variable.equals(QUESTION_MARK) ? column : variable);
    } else if (ctx.K_TOKEN() != null) {
        CQLFragment variable = visitTerm(ctx.term().get(0));
        if (variable instanceof CQLWord) {
            if (variable == QUESTION_MARK) {
                variable = INTERNAL_TOKEN_VARNAME;
            }
            if (ctx.relationType().getText().equals(">")) {
                tokenRangeRestrictionStartVariable = (CQLWord) variable;
                tokenRangeRestrictionStartVariableIndex = tokenRangeRestrictionVariableIndex++;
            } else if (ctx.relationType().getText().equals("<=")) {
                tokenRangeRestrictionEndVariable = (CQLWord) variable;
                tokenRangeRestrictionEndVariableIndex = tokenRangeRestrictionVariableIndex++;
            }
        }
    }
    // other relation types: unsupported
    return null;
}
Also used : CidentContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.CidentContext) RelationTypeContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.RelationTypeContext) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) TermContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Aggregations

CQLFragment (com.datastax.oss.dsbulk.mapping.CQLFragment)14 CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)11 FunctionCall (com.datastax.oss.dsbulk.mapping.FunctionCall)7 IndexedMappingField (com.datastax.oss.dsbulk.mapping.IndexedMappingField)6 MappedMappingField (com.datastax.oss.dsbulk.mapping.MappedMappingField)6 MappingField (com.datastax.oss.dsbulk.mapping.MappingField)6 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)4 ImmutableMultimap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMultimap)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)4 Nullable (edu.umd.cs.findbugs.annotations.Nullable)4 ArrayList (java.util.ArrayList)4 DseGraphKeyspaceMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphKeyspaceMetadata)3 CQLLiteral (com.datastax.oss.dsbulk.mapping.CQLLiteral)3 TypedCQLLiteral (com.datastax.oss.dsbulk.mapping.TypedCQLLiteral)3 DseEdgeMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata)2 DseGraphTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata)2 DseTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseTableMetadata)2 DseVertexMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseVertexMetadata)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2