use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class QueryParser method parseSelectExpression.
public Expression parseSelectExpression(String sql) throws QueryParserException {
if (sql == null) {
// $NON-NLS-1$
throw new IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr"));
}
ParseInfo dummyInfo = new ParseInfo();
Expression result = null;
try {
result = getSqlParser(sql).selectExpression(dummyInfo);
} catch (ParseException pe) {
throw convertParserException(pe);
} finally {
tm.reinit();
}
return result;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class QueryParser method parseExpression.
/**
* Takes a SQL string representing an SQL expression
* and returns the object representation.
* @param sql SQL expression string
* @return SQL expression object
* @throws QueryParserException if parsing fails
* @throws IllegalArgumentException if sql is null
*/
public Expression parseExpression(String sql) throws QueryParserException {
if (sql == null) {
// $NON-NLS-1$
throw new IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr"));
}
ParseInfo dummyInfo = new ParseInfo();
Expression result = null;
try {
result = getSqlParser(sql).expression(dummyInfo);
} catch (ParseException pe) {
throw convertParserException(pe);
} finally {
tm.reinit();
}
return result;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class SQLParserUtil method addFBI.
KeyRecord addFBI(MetadataFactory factory, List<Expression> expressions, Table table, String name) throws MetadataException {
List<String> columnNames = new ArrayList<String>(expressions.size());
List<Boolean> nonColumnExpressions = new ArrayList<Boolean>(expressions.size());
boolean fbi = false;
for (int i = 0; i < expressions.size(); i++) {
Expression ex = expressions.get(i);
if (ex instanceof ElementSymbol) {
columnNames.add(((ElementSymbol) ex).getName());
nonColumnExpressions.add(Boolean.FALSE);
} else {
columnNames.add(ex.toString());
nonColumnExpressions.add(Boolean.TRUE);
fbi = true;
}
}
return factory.addFunctionBasedIndex(name != null ? name : (SQLConstants.NonReserved.INDEX + (fbi ? table.getFunctionBasedIndexes().size() : table.getIndexes().size())), columnNames, nonColumnExpressions, table);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestUpdateValidator method createView.
public static Command createView(String sql, TransformationMetadata md, String vGroup) throws QueryParserException, QueryResolverException, TeiidComponentException {
QueryNode vm1g1n1 = new QueryNode(sql);
Table vm1g1 = RealMetadataFactory.createUpdatableVirtualGroup(vGroup, md.getMetadataStore().getSchema("VM1"), vm1g1n1);
Command command = QueryParser.getQueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, md);
List<Expression> symbols = command.getProjectedSymbols();
String[] names = new String[symbols.size()];
String[] types = new String[symbols.size()];
int i = 0;
for (Expression singleElementSymbol : symbols) {
names[i] = Symbol.getShortName(singleElementSymbol);
types[i++] = DataTypeManager.getDataTypeName(singleElementSymbol.getType());
}
RealMetadataFactory.createElements(vm1g1, names, types);
return command;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestQueryRewriter method testCaseExpressionThatResolvesToNull.
@Test
public void testCaseExpressionThatResolvesToNull() {
// $NON-NLS-1$
String sqlBefore = "SELECT CASE 'x' WHEN 'Old Inventory System' THEN NULL WHEN 'New Inventory System' THEN NULL END";
// $NON-NLS-1$
String sqlAfter = "SELECT null";
Command cmd = helpTestRewriteCommand(sqlBefore, sqlAfter);
Expression es = cmd.getProjectedSymbols().get(0);
assertEquals(DataTypeManager.DefaultDataClasses.STRING, es.getType());
}
Aggregations