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();
}
}
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;
}
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();
}
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;
}
}
Aggregations