Skip to content

Commit

Permalink
TEIIDDES-3034
Browse files Browse the repository at this point in the history
 * now catching this specific use-case and properly constructing and
naming the result set as well as naming result set column to match the
SQL aliased projected symbol
  • Loading branch information
blafond committed Jun 29, 2017
1 parent 1500882 commit ef40770
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ protected RelationalProcedure createVirtualProcedure(AstNode procedureNode, Rela
} else if(is(child, TeiidDdlLexicon.CreateProcedure.RESULT_COLUMNS)) {
RelationalProcedureResultSet result = getFactory().createProcedureResultSet();
procedure.setResultSet(result);
initialize(result, procedureNode);
initialize(result, procedureNode, child.getName());

List<AstNode> resultOptionNodes = new ArrayList<AstNode>();

Expand All @@ -629,9 +629,20 @@ protected RelationalProcedure createVirtualProcedure(AstNode procedureNode, Rela
processOptions(resultOptionNodes, result);

} else if(is(child, TeiidDdlLexicon.CreateProcedure.RESULT_DATA_TYPE)) {
// Add a parameter with RETURN direction
RelationalParameter param = createProcedureParameter(child, procedure);
param.setDirection(DirectionKind.RETURN_LITERAL.toString());
RelationalProcedureResultSet result = getFactory().createProcedureResultSet();
procedure.setResultSet(result);
initialize(result, procedureNode, "resultSet");

RelationalColumn newColumn = createColumn(child,result);
// name the new column with the child name property
// newColumn.setName(child.getName());

// // Add a parameter with RETURN direction
// RelationalParameter param = createProcedureParameter(child, procedure);
// if( param.getName().equalsIgnoreCase("resultSet") ) {
// param.setName("result");
// }
// param.setDirection(DirectionKind.RETURN_LITERAL.toString());
} else if(is(child, StandardDdlLexicon.TYPE_STATEMENT_OPTION)) {
procOptionNodes.add(child);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelUtil;
import org.teiid.designer.metamodels.relational.Column;
import org.teiid.designer.metamodels.relational.DirectionKind;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.metamodels.relational.ProcedureParameter;
import org.teiid.designer.metamodels.relational.ProcedureResult;
import org.teiid.designer.metamodels.transformation.MappingClass;
import org.teiid.designer.metamodels.transformation.SqlAlias;
import org.teiid.designer.metamodels.transformation.SqlTransformationMappingRoot;
Expand Down Expand Up @@ -741,30 +744,57 @@ public static IStatus reconcileTargetAttributes( EObject transMappingRoot,
// Get the list of unMatchedNames in the VirtualGroup
List unmatchedVirtualNames = removeNames(currentTargetAttrNames, matchedNames);

if (unmatchedVirtualNames.size() != 0) {
// Modify query if there's a name conflict
resetSelectSqlOnNameConflict(validCommand, transMappingRoot, true, txnSource);
return TRANSFORMATION_ISSUE;
}

// Get the list of Extra Names in the Select List
List extraSymbolNames = removeNames(projectedSymbolNames, matchedNames);

if (unmatchedVirtualNames.size() != 0) {
if (targetGroup instanceof ProcedureResult && unmatchedVirtualNames.contains("resultSet")
&& extraSymbolNames.size() == 1 ) {
// we have a simple result parameter
// then reset the name of result set column IF there is only one of them
ProcedureResult result = (ProcedureResult)targetGroup;
if( result != null && result.getColumns().size() == 1) {
ModelerCore.getModelEditor().rename((EObject)result.getColumns().get(0), (String)extraSymbolNames.get(0));
extraSymbolNames.clear();
}
} else {
// Modify query if there's a name conflict
resetSelectSqlOnNameConflict(validCommand, transMappingRoot, true, txnSource);
return TRANSFORMATION_ISSUE;
}
}

// Add the New Elements to the Target Group
if (extraSymbolNames.size() != 0) {
//create a resultset if none exists
if (TransformationHelper.isSqlProcedure(targetGroup)) {
SqlProcedureAspect procAspect = (SqlProcedureAspect)AspectManager.getSqlAspect(targetGroup);
EObject rs = (EObject)procAspect.getResult(targetGroup);
if (rs == null) {
targetGroup = TransformationHelper.createProcResultSet(targetGroup);
}
if (rs == null); {
boolean hasReturnParam = false;
// Look at parameters and do not add a result set if there is a RETURNS direction on one
for( Object child : procAspect.getParameters(targetGroup) ) {
ProcedureParameter param = (ProcedureParameter)child;
if( param.getDirection().getValue() == DirectionKind.RETURN) {
hasReturnParam = true;
// extraSymbolNames.remove("result");
break;
}
}

if( !hasReturnParam ) {
targetGroup = TransformationHelper.createProcResultSet(targetGroup);
}
}
}

// Get the Map of ProjectedSymbol Name to the corresponding EObject (if exists)
Map eObjectMap = TransformationSqlHelper.getProjectedSymbolAndProcInputEObjects(validCommand);

addTargetAttributes(extraSymbolNames, eObjectMap, targetGroup, txnSource);
if( !extraSymbolNames.isEmpty() ) {
// Get the Map of ProjectedSymbol Name to the corresponding EObject (if exists)
Map eObjectMap = TransformationSqlHelper.getProjectedSymbolAndProcInputEObjects(validCommand);

addTargetAttributes(extraSymbolNames, eObjectMap, targetGroup, txnSource);
}
changed = true;
}
}
Expand Down Expand Up @@ -796,7 +826,9 @@ public static IStatus reconcileTargetAttributes( EObject transMappingRoot,
changed = AttributeMappingHelper.updateAttributeMappings(transMappingRoot, txnSource) || changed;

succeeded = true;
} finally {
} catch (ModelerCoreException e) {
TransformationPlugin.Util.log(IStatus.ERROR, e, "Problem reconciling SQL to target attributes");
} finally {
if (requiredStart) {
if (succeeded) {
ModelerCore.commitTxn();
Expand Down

0 comments on commit ef40770

Please sign in to comment.