use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestResolver method testStringConversion2.
@Test
public void testStringConversion2() {
// 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(conversion);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(e1);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("'2003-02-27'=pm3.g1.e2");
// if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
// fail("Left expressions not equal");
// } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
// fail("Right expressions not equal");
// }
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestResolver method test11716.
@Test
public void test11716() throws Exception {
// $NON-NLS-1$
String sql = "SELECT e1 FROM pm1.g1 where e1='1'";
Map externalMetadata = new HashMap();
// $NON-NLS-1$
GroupSymbol inputSet = new GroupSymbol("INPUT");
List inputSetElements = new ArrayList();
// $NON-NLS-1$
ElementSymbol inputSetElement = new ElementSymbol("INPUT.e1");
inputSetElements.add(inputSetElement);
externalMetadata.put(inputSet, inputSetElements);
Query command = (Query) helpParse(sql);
QueryResolver.resolveCommand(command, metadata);
Collection groups = GroupCollectorVisitor.getGroups(command, false);
assertFalse(groups.contains(inputSet));
}
use of org.teiid.query.sql.symbol.ElementSymbol 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.ElementSymbol in project teiid by teiid.
the class TestResolver method helpCheckElements.
private void helpCheckElements(LanguageObject langObj, String[] elementNames, String[] elementIDs) {
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
ElementCollectorVisitor.getElements(langObj, elements);
// $NON-NLS-1$
assertEquals("Wrong number of elements: ", elementNames.length, elements.size());
for (int i = 0; i < elements.size(); i++) {
ElementSymbol symbol = elements.get(i);
// $NON-NLS-1$
assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase());
Object elementID = symbol.getMetadataID();
try {
String name = metadata.getFullName(elementID);
// $NON-NLS-1$ //$NON-NLS-2$
assertNotNull("ElementSymbol " + symbol + " was not resolved and has no metadataID", elementID);
// $NON-NLS-1$
assertEquals("ElementID name does not match: ", elementIDs[i].toUpperCase(), name.toUpperCase());
} catch (TeiidComponentException e) {
throw new RuntimeException(e);
}
}
}
use of org.teiid.query.sql.symbol.ElementSymbol 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);
}
Aggregations