Search in sources :

Example 1 with TDSColumn

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");
    }
}
Also used : Function(org.eclipse.collections.api.block.function.Function) TDSColumn(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn) ResultSet(java.sql.ResultSet) Root_meta_pure_tds_TDSColumn_Impl(org.finos.legend.pure.generated.Root_meta_pure_tds_TDSColumn_Impl) TDSBuilder(org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder) Root_meta_pure_tds_TDSNull(org.finos.legend.pure.generated.Root_meta_pure_tds_TDSNull) Root_meta_pure_tds_TDSNull_Impl(org.finos.legend.pure.generated.Root_meta_pure_tds_TDSNull_Impl)

Example 2 with TDSColumn

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);
    }
}
Also used : LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) DatabaseManager(org.finos.legend.engine.plan.execution.stores.relational.connection.driver.DatabaseManager) Serializer(org.finos.legend.engine.plan.execution.result.serialization.Serializer) DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) Connection(java.sql.Connection) ClassMappingInfo(org.finos.legend.engine.plan.execution.result.builder._class.ClassMappingInfo) ExecutionNodeTDSResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeTDSResultHelper) SerializationFormat(org.finos.legend.engine.plan.execution.result.serialization.SerializationFormat) RelationalInstantiationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.RelationalInstantiationExecutionNode) TransformerInput(org.finos.legend.engine.plan.execution.result.transformer.TransformerInput) MutableList(org.eclipse.collections.api.list.MutableList) TDSColumn(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn) ResultSet(java.sql.ResultSet) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) RelationBuilder(org.finos.legend.engine.plan.execution.stores.relational.result.builder.relation.RelationBuilder) Builder(org.finos.legend.engine.plan.execution.result.builder.Builder) IRelationalResult(org.finos.legend.engine.plan.dependencies.store.relational.IRelationalResult) SQLResultColumn(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.result.SQLResultColumn) GregorianCalendar(java.util.GregorianCalendar) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) StreamingResult(org.finos.legend.engine.plan.execution.result.StreamingResult) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) RelationalResultToPureTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSSerializer) List(java.util.List) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) Lists(org.eclipse.collections.impl.factory.Lists) PureDate(org.finos.legend.engine.plan.dependencies.domain.date.PureDate) ExecutionNodeClassResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeClassResultHelper) Span(io.opentracing.Span) PropertyInfo(org.finos.legend.engine.plan.execution.result.builder._class.PropertyInfo) ResultSetMetaData(java.sql.ResultSetMetaData) Types(java.sql.Types) CommonProfile(org.pac4j.core.profile.CommonProfile) RelationalExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.RelationalExecutionNode) Function(org.eclipse.collections.api.block.function.Function) ExecutionActivity(org.finos.legend.engine.plan.execution.result.ExecutionActivity) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) SQLException(java.sql.SQLException) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) RelationalExecutionActivity(org.finos.legend.engine.plan.execution.stores.relational.activity.RelationalExecutionActivity) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) Result(org.finos.legend.engine.plan.execution.result.Result) ResultVisitor(org.finos.legend.engine.plan.execution.result.ResultVisitor) Logger(org.slf4j.Logger) ListIterate(org.eclipse.collections.impl.utility.ListIterate) ClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.ClassBuilder) SetImplTransformers(org.finos.legend.engine.plan.execution.result.transformer.SetImplTransformers) DataTypeBuilder(org.finos.legend.engine.plan.execution.result.builder.datatype.DataTypeBuilder) ExecutionNodePartialClassResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodePartialClassResultHelper) Consumer(java.util.function.Consumer) RelationalResultToCSVSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToCSVSerializer) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Statement(java.sql.Statement) RelationalResultToPureTDSToObjectSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSToObjectSerializer) TDSBuilder(org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) SetImplTransformers(org.finos.legend.engine.plan.execution.result.transformer.SetImplTransformers) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) ClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.ClassBuilder) TransformerInput(org.finos.legend.engine.plan.execution.result.transformer.TransformerInput) SQLException(java.sql.SQLException) ClassMappingInfo(org.finos.legend.engine.plan.execution.result.builder._class.ClassMappingInfo) DataTypeBuilder(org.finos.legend.engine.plan.execution.result.builder.datatype.DataTypeBuilder) TDSColumn(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn) RelationBuilder(org.finos.legend.engine.plan.execution.stores.relational.result.builder.relation.RelationBuilder) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) ImmutableList(org.eclipse.collections.api.list.ImmutableList) TDSBuilder(org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder) PropertyInfo(org.finos.legend.engine.plan.execution.result.builder._class.PropertyInfo)

Aggregations

ResultSet (java.sql.ResultSet)2 Function (org.eclipse.collections.api.block.function.Function)2 TDSBuilder (org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder)2 Span (io.opentracing.Span)1 Connection (java.sql.Connection)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1 Types (java.sql.Types)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1 Consumer (java.util.function.Consumer)1 ImmutableList (org.eclipse.collections.api.list.ImmutableList)1 MutableList (org.eclipse.collections.api.list.MutableList)1 Lists (org.eclipse.collections.impl.factory.Lists)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 PureDate (org.finos.legend.engine.plan.dependencies.domain.date.PureDate)1 IRelationalResult (org.finos.legend.engine.plan.dependencies.store.relational.IRelationalResult)1