Skip to content

Commit

Permalink
TEIID-3994 addressing alias symbol wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Mar 1, 2016
1 parent bf19d7e commit 071f0f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public Map<ElementSymbol, Expression> getVariableValues(Command command, boolean
if (!changingOnly) {
varSymbol = next.clone();
varSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
result.put(varSymbol, (Expression)valIter.next());
result.put(varSymbol, SymbolMap.getExpression((Expression)valIter.next()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,27 @@ public class TestTriggerActions {
List<?>[] expected = new List[] {Arrays.asList(2)};
helpProcess(plan, context, dm, expected);
}

@Test public void testInsertWithQueryExpressionAndAlias() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL(
"create foreign table tablea (TEST_ID integer, TEST_NBR bigdecimal) options (updatable true);\n" +
"create foreign table tableb (TEST_ID integer, TEST_NBR bigdecimal);\n" +
"create view viewa options (updatable true) as SELECT TEST_ID, TEST_NBR FROM tablea;\n" +
"create trigger on viewa instead of insert as for each row begin atomic "
+ "INSERT INTO tablea (tablea.TEST_ID, tablea.TEST_NBR) VALUES (\"NEW\".TEST_ID, \"NEW\".TEST_NBR); END;"
, "x", "y");

String sql = "insert into viewa (TEST_ID, TEST_NBR) SELECT TEST_ID AS X, TEST_NBR FROM tableb";

HardcodedDataManager dm = new HardcodedDataManager();
dm.addData("INSERT INTO tablea (TEST_ID, TEST_NBR) VALUES (1, 2.0)", Arrays.asList(1));
dm.addData("SELECT g_0.TEST_ID, g_0.TEST_NBR FROM y.tableb AS g_0", Arrays.asList(1, 2.0));

CommandContext context = createCommandContext();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
List<?>[] expected = new List[] {Arrays.asList(1)};
helpProcess(plan, context, dm, expected);
}

}

0 comments on commit 071f0f0

Please sign in to comment.