Search in sources :

Example 1 with SoqlQuery

use of org.talend.components.salesforce.soql.SoqlQuery in project components by Talend.

the class SalesforceBulkQueryInputReader method getModuleName.

private String getModuleName() {
    TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
    if (inProperties.manualQuery.getValue()) {
        SoqlQuery query = SoqlQuery.getInstance();
        query.init(inProperties.query.getValue());
        return query.getDrivingEntityName();
    } else {
        return properties.module.moduleName.getValue();
    }
}
Also used : SoqlQuery(org.talend.components.salesforce.soql.SoqlQuery) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 2 with SoqlQuery

use of org.talend.components.salesforce.soql.SoqlQuery in project components by Talend.

the class SalesforceDataprepSource method guessSchema.

@Override
public Schema guessSchema(String soqlQuery) throws IOException {
    SoqlQuery query = SoqlQuery.getInstance();
    query.init(soqlQuery);
    List<FieldDescription> fieldDescriptions = query.getFieldDescriptions();
    String drivingEntityName = query.getDrivingEntityName();
    DescribeSObjectResult describeSObjectResult = null;
    try {
        describeSObjectResult = connectionHolder.connection.describeSObject(drivingEntityName);
    } catch (ConnectionException e) {
        throw new RuntimeException(e);
    }
    Schema runtimeSchema = SalesforceAvroRegistryString.get().inferSchema(describeSObjectResult);
    Schema newSchema = Schema.createRecord("GuessedSchema", runtimeSchema.getDoc(), runtimeSchema.getNamespace(), runtimeSchema.isError());
    List<Schema.Field> newFieldList = new ArrayList<>();
    for (FieldDescription fieldDescription : fieldDescriptions) {
        Schema.Field runtimeField = runtimeSchema.getField(fieldDescription.getFullName());
        if (runtimeField != null) {
            Schema.Field newField = new Schema.Field(runtimeField.name(), runtimeField.schema(), runtimeField.doc(), runtimeField.defaultVal(), runtimeField.order());
            newField.getObjectProps().putAll(runtimeField.getObjectProps());
            for (Map.Entry<String, Object> entry : runtimeField.getObjectProps().entrySet()) {
                newField.addProp(entry.getKey(), entry.getValue());
            }
            newFieldList.add(newField);
        } else {
            Schema.Field newField = new Schema.Field(fieldDescription.getFullName(), AvroUtils._string(), null, (String) null);
            newFieldList.add(newField);
        }
    }
    newSchema.setFields(newFieldList);
    for (Map.Entry<String, Object> entry : runtimeSchema.getObjectProps().entrySet()) {
        newSchema.addProp(entry.getKey(), entry.getValue());
    }
    return newSchema;
}
Also used : DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) FieldDescription(org.talend.components.salesforce.soql.FieldDescription) SoqlQuery(org.talend.components.salesforce.soql.SoqlQuery) Map(java.util.Map) ConnectionException(com.sforce.ws.ConnectionException)

Example 3 with SoqlQuery

use of org.talend.components.salesforce.soql.SoqlQuery in project components by Talend.

the class SalesforceSourceOrSink method guessSchema.

@Override
public Schema guessSchema(String soqlQuery) throws IOException {
    SoqlQuery query = SoqlQuery.getInstance();
    query.init(soqlQuery);
    SchemaBuilder.FieldAssembler fieldAssembler = SchemaBuilder.record("GuessedSchema").fields();
    DescribeSObjectResult describeSObjectResult = null;
    try {
        describeSObjectResult = connect(null).connection.describeSObject(query.getDrivingEntityName());
    } catch (ConnectionException e) {
        throw new RuntimeException(e.getMessage());
    }
    Schema entitySchema = SalesforceAvroRegistry.get().inferSchema(describeSObjectResult);
    for (FieldDescription fieldDescription : query.getFieldDescriptions()) {
        Schema.Field schemaField = entitySchema.getField(fieldDescription.getSimpleName());
        SchemaBuilder.FieldBuilder builder = fieldAssembler.name(fieldDescription.getFullName());
        Schema fieldType = null;
        if (schemaField != null) {
            Map<String, Object> props = schemaField.getObjectProps();
            for (Map.Entry<String, Object> entry : props.entrySet()) {
                builder.prop(entry.getKey(), String.valueOf(entry.getValue()));
            }
            fieldType = schemaField.schema();
        } else {
            fieldType = DEFAULT_GUESS_SCHEMA_TYPE;
        }
        builder.type(fieldType).noDefault();
    }
    return (Schema) fieldAssembler.endRecord();
}
Also used : DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) FieldDescription(org.talend.components.salesforce.soql.FieldDescription) SchemaBuilder(org.apache.avro.SchemaBuilder) SoqlQuery(org.talend.components.salesforce.soql.SoqlQuery) Map(java.util.Map) ConnectionException(com.sforce.ws.ConnectionException)

Example 4 with SoqlQuery

use of org.talend.components.salesforce.soql.SoqlQuery in project components by Talend.

the class SalesforceBulkQueryReader method getModuleName.

private String getModuleName() {
    if (dataset.sourceType.getValue() == SourceType.MODULE_SELECTION) {
        return dataset.moduleName.getValue();
    } else {
        String query = dataset.query.getValue();
        if (query != null && !query.isEmpty()) {
            SoqlQuery soqlInstance = SoqlQuery.getInstance();
            soqlInstance.init(query);
            return soqlInstance.getDrivingEntityName();
        }
        return null;
    }
}
Also used : SoqlQuery(org.talend.components.salesforce.soql.SoqlQuery)

Aggregations

SoqlQuery (org.talend.components.salesforce.soql.SoqlQuery)4 DescribeSObjectResult (com.sforce.soap.partner.DescribeSObjectResult)2 ConnectionException (com.sforce.ws.ConnectionException)2 Map (java.util.Map)2 Schema (org.apache.avro.Schema)2 FieldDescription (org.talend.components.salesforce.soql.FieldDescription)2 ArrayList (java.util.ArrayList)1 SchemaBuilder (org.apache.avro.SchemaBuilder)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1