use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn in project legend-engine by finos.
the class ResultToPureResultVisitor method visit.
@Override
public Result<Object> visit(RelationalResult relationalResult) {
// Build Pure Result
if (relationalResult.builder instanceof TDSBuilder) {
org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result<Object> res = new org.finos.legend.pure.generated.Root_meta_pure_mapping_Result_Impl<Object>("Res");
try {
org.finos.legend.pure.generated.Root_meta_pure_tds_TabularDataSet set = new org.finos.legend.pure.generated.Root_meta_pure_tds_TabularDataSet_Impl("TDS");
ResultSet rset = relationalResult.resultSet;
MutableList<Function<Object, Object>> transformers = relationalResult.getTransformers();
Root_meta_pure_tds_TDSNull tdsNull = new Root_meta_pure_tds_TDSNull_Impl("");
while (rset.next()) {
org.finos.legend.pure.generated.Root_meta_pure_tds_TDSRow row = new org.finos.legend.pure.generated.Root_meta_pure_tds_TDSRow_Impl("");
for (int i = 1; i <= relationalResult.columnCount - 1; i++) {
Object obj = relationalResult.getValue(i);
row._valuesAdd(obj == null ? tdsNull : transformers.get(i - 1).valueOf(obj));
}
Object obj = relationalResult.getValue(relationalResult.columnCount);
row._valuesAdd(obj == null ? tdsNull : transformers.get(relationalResult.columnCount - 1).valueOf(obj));
row._parent(set);
set._rowsAdd(row);
}
for (int i = 0; i < relationalResult.columnCount; i++) {
TDSColumn col = relationalResult.getTdsColumns().get(i);
set._columnsAdd(new Root_meta_pure_tds_TDSColumn_Impl(col.name)._offset((long) i)._name(col.name));
}
res._valuesAdd(set);
return res;
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("To Code");
}
}
use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn 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