use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method helpCheckSelect.
private void helpCheckSelect(Query query, String[] elementNames) {
Select select = query.getSelect();
List<Expression> elements = select.getProjectedSymbols();
// $NON-NLS-1$
assertEquals("Wrong number of select symbols: ", elementNames.length, elements.size());
for (int i = 0; i < elements.size(); i++) {
Expression symbol = elements.get(i);
String name = Symbol.getShortName(symbol);
if (symbol instanceof ElementSymbol) {
name = ((ElementSymbol) symbol).getName();
}
// $NON-NLS-1$
assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), name.toString().toUpperCase());
}
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testStringConversion1.
@Test
public void testStringConversion1() {
// Expected left expression
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
e1.setType(DataTypeManager.DefaultDataClasses.DATE);
// Expected right expression
Class srcType = DataTypeManager.DefaultDataClasses.STRING;
String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
// $NON-NLS-1$
Expression expression = new Constant("2003-02-27");
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
conversion.setFunctionDescriptor(fd);
conversion.makeImplicit();
// Expected criteria
CompareCriteria expected = new CompareCriteria();
expected.setLeftExpression(e1);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(conversion);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e2='2003-02-27'");
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testUpdateSetClauseReferenceType.
@Test
public void testUpdateSetClauseReferenceType() {
// $NON-NLS-1$
String sql = "UPDATE pm1.g1 SET pm1.g1.e1 = 1, pm1.g1.e2 = ?;";
Update update = (Update) helpResolve(sql, RealMetadataFactory.example1Cached());
Expression ref = update.getChangeList().getClauses().get(1).getValue();
assertTrue(ref instanceof Reference);
assertNotNull(ref.getType());
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testNullConstantInSelect.
@Test
public void testNullConstantInSelect() throws Exception {
// $NON-NLS-1$
String userSql = "SELECT null as x";
Query query = (Query) helpParse(userSql);
QueryResolver.resolveCommand(query, RealMetadataFactory.exampleBQTCached());
// Check type of resolved null constant
Expression symbol = query.getSelect().getSymbols().get(0);
assertNotNull(symbol.getType());
assertEquals(DataTypeManager.DefaultDataClasses.STRING, symbol.getType());
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testExecProjectedSymbols.
@Test
public void testExecProjectedSymbols() {
// $NON-NLS-1$
String query = "exec pm1.sq1()";
StoredProcedure proc = (StoredProcedure) helpResolve(query);
List<Expression> projected = proc.getProjectedSymbols();
assertEquals(2, projected.size());
for (Iterator<Expression> i = projected.iterator(); i.hasNext(); ) {
ElementSymbol symbol = (ElementSymbol) i.next();
assertNotNull(symbol.getGroupSymbol());
}
}
Aggregations