Search in sources :

Example 21 with CQLWord

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

the class DefaultRecordMapper method bindStatement.

private MappedBoundStatement bindStatement(Record record, PreparedStatement insertStatement) {
    BoundStatementBuilder builder = boundStatementBuilderFactory.apply(insertStatement);
    ColumnDefinitions variableDefinitions = insertStatement.getVariableDefinitions();
    for (Field field : record.fields()) {
        Set<CQLWord> variables = mapping.fieldToVariables(field);
        for (CQLWord variable : variables) {
            CqlIdentifier name = variable.asIdentifier();
            if (size == 1 || variableDefinitions.contains(name)) {
                DataType cqlType = variableDefinitions.get(name).getType();
                GenericType<?> fieldType = recordMetadata.getFieldType(field, cqlType);
                Object raw = record.getFieldValue(field);
                builder = bindColumn(builder, field, variable, raw, cqlType, fieldType);
            }
        }
    }
    ensurePrimaryKeySet(builder);
    if (protocolVersion.getCode() < DefaultProtocolVersion.V4.getCode()) {
        ensureAllVariablesSet(builder, insertStatement);
    }
    BoundStatement bs = builder.build();
    return new MappedBoundStatement(record, bs);
}
Also used : Field(com.datastax.oss.dsbulk.connectors.api.Field) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) DataType(com.datastax.oss.driver.api.core.type.DataType) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) MappedBoundStatement(com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) MappedBoundStatement(com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Example 22 with CQLWord

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

the class QueryInspector method visitUsingTimestamp.

@Nullable
private CQLWord visitUsingTimestamp(IntValueContext intValueContext) {
    if (intValueContext.noncolIdent() != null) {
        CQLWord variable = visitNoncolIdent(intValueContext.noncolIdent());
        writeTimeVariablesBuilder.add(variable);
        usingTimestampVariable = variable;
    } else if (intValueContext.QMARK() != null) {
        writeTimeVariablesBuilder.add(INTERNAL_TIMESTAMP_VARNAME);
        usingTimestampVariable = INTERNAL_TIMESTAMP_VARNAME;
    }
    return usingTimestampVariable;
}
Also used : CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 23 with CQLWord

use of com.datastax.oss.dsbulk.mapping.CQLWord 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

CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)23 CQLFragment (com.datastax.oss.dsbulk.mapping.CQLFragment)12 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)8 RecordMapper (com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper)8 Config (com.typesafe.config.Config)8 EnumSet (java.util.EnumSet)8 Set (java.util.Set)8 DefaultMapping (com.datastax.oss.dsbulk.mapping.DefaultMapping)7 FunctionCall (com.datastax.oss.dsbulk.mapping.FunctionCall)7 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)6 Field (com.datastax.oss.dsbulk.connectors.api.Field)6 IndexedMappingField (com.datastax.oss.dsbulk.mapping.IndexedMappingField)6 MappedMappingField (com.datastax.oss.dsbulk.mapping.MappedMappingField)6 MappingField (com.datastax.oss.dsbulk.mapping.MappingField)6 NonNull (edu.umd.cs.findbugs.annotations.NonNull)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)5 DataType (com.datastax.oss.driver.api.core.type.DataType)5 ArrayList (java.util.ArrayList)5