use of org.finos.legend.engine.plan.execution.result.builder._class.ClassMappingInfo in project legend-engine by finos.
the class RelationalResult method buildTransformersAndBuilder.
private void buildTransformersAndBuilder(ExecutionNode node, DatabaseConnection databaseConnection) throws SQLException {
boolean isDatabaseIdentifiersCaseSensitive = databaseConnection.accept(new DatabaseIdentifiersCaseSensitiveVisitor());
if (ExecutionNodeTDSResultHelper.isResultTDS(node)) {
List<TransformerInput<Integer>> transformerInputs = Lists.mutable.empty();
for (int columnIndex = 1; columnIndex <= this.columnCount; columnIndex++) {
TDSColumn c = ExecutionNodeTDSResultHelper.getTDSColumn(node, this.resultSetMetaData.getColumnLabel(columnIndex), isDatabaseIdentifiersCaseSensitive);
transformerInputs.add(new TransformerInput<>(columnIndex, c.type, (index) -> {
try {
return ExecutionNodeTDSResultHelper.isTDSColumnEnum(node, this.resultSetMetaData.getColumnLabel(index), isDatabaseIdentifiersCaseSensitive);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, (index) -> {
try {
return ExecutionNodeTDSResultHelper.getTDSEnumTransformer(node, this.resultSetMetaData.getColumnLabel(index), isDatabaseIdentifiersCaseSensitive);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
setTransformers.add(new SetImplTransformers(transformerInputs));
this.builder = new TDSBuilder(node, this.sqlColumns, isDatabaseIdentifiersCaseSensitive);
this.columnListForSerializer = ListIterate.collect(((TDSBuilder) this.builder).columns, col -> col.name);
} else if (ExecutionNodeClassResultHelper.isClassResult(node)) {
List<? extends ClassMappingInfo> classMappings = ExecutionNodeClassResultHelper.getClassMappingInfoFromClassResult(node);
for (ClassMappingInfo classMappingInfo : classMappings) {
List<TransformerInput<String>> transformerInputs = Lists.mutable.empty();
for (int i = 1; i <= this.columnCount; i++) {
final String colName = this.resultSetMetaData.getColumnLabel(i);
PropertyInfo profiles = ListIterate.select(classMappingInfo.properties, p -> isDatabaseIdentifiersCaseSensitive ? p.property.equals(colName) : p.property.equalsIgnoreCase(colName)).getFirst();
transformerInputs.add(new TransformerInput<>(profiles != null ? profiles.property : colName, resolveType(profiles, colName), (colNameX) -> {
try {
return !TEMPORAL_DATE_ALIASES.contains(colNameX) && ExecutionNodeClassResultHelper.isClassPropertyEnum(node, classMappingInfo.setImplementationId, colNameX);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, (colNameX) -> {
try {
return ExecutionNodeClassResultHelper.getClassEnumTransformer(node, classMappingInfo.setImplementationId, colNameX);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
setTransformers.add(new SetImplTransformers(transformerInputs));
if (ExecutionNodePartialClassResultHelper.isPartialClassResult(node)) {
this.builder = new PartialClassBuilder(node);
} else {
this.builder = new ClassBuilder(node);
}
}
} else if (ExecutionNodeRelationalResultHelper.isRelationResult(node)) {
SetImplTransformers setImpl = new SetImplTransformers();
for (int columnIndex = 1; columnIndex <= this.columnCount; columnIndex++) {
setImpl.transformers.add(SetImplTransformers.TEMPORARY_DATATYPE_TRANSFORMER);
}
setTransformers.add(setImpl);
this.builder = new RelationBuilder(node);
} else {
SetImplTransformers setImpl = new SetImplTransformers();
for (int i = 1; i <= this.columnCount; i++) {
setImpl.transformers.add(SetImplTransformers.TEMPORARY_DATATYPE_TRANSFORMER);
}
setTransformers.add(setImpl);
this.builder = new DataTypeBuilder(node);
}
}
Aggregations