Search in sources :

Example 31 with Expression

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;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression)

Example 32 with Expression

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;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression)

Example 33 with Expression

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)

Example 34 with Expression

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;
}
Also used : Table(org.teiid.metadata.Table) Command(org.teiid.query.sql.lang.Command) Expression(org.teiid.query.sql.symbol.Expression) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 35 with Expression

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());
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) Test(org.junit.Test)

Aggregations

Expression (org.teiid.query.sql.symbol.Expression)257 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)104 ArrayList (java.util.ArrayList)74 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)54 Test (org.junit.Test)53 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 List (java.util.List)49 Constant (org.teiid.query.sql.symbol.Constant)38 SymbolMap (org.teiid.query.sql.util.SymbolMap)37 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)22 Criteria (org.teiid.query.sql.lang.Criteria)22 Map (java.util.Map)21 ClobType (org.teiid.core.types.ClobType)16 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)16 HashSet (java.util.HashSet)13 LinkedHashSet (java.util.LinkedHashSet)13 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)13 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)13 OrderBy (org.teiid.query.sql.lang.OrderBy)12