Search in sources :

Example 1 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class EvaluatorIterator method init.

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        GroupSymbol gs = null;
        String query = options.get(QUERYSTRING);
        TransformationMetadata tm = createTransformationMetadata(options.get(DDL));
        this.criteria = QueryParser.getQueryParser().parseCriteria(query);
        this.elementsInExpression = ElementCollectorVisitor.getElements(this.criteria, false);
        for (ElementSymbol es : this.elementsInExpression) {
            gs = es.getGroupSymbol();
            ResolverUtil.resolveGroup(gs, tm);
        }
        ResolverVisitor.resolveLanguageObject(this.criteria, tm);
        this.evaluatorUtil = new EvaluatorUtil(gs);
    } catch (QueryParserException e) {
        throw new IOException(e);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } catch (QueryResolverException e) {
        throw new IOException(e);
    } catch (TeiidComponentException e) {
        throw new IOException(e);
    }
    CommandContext cc = new CommandContext();
    this.evaluator = new Evaluator(this.evaluatorUtil.getElementMap(), null, cc);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryParserException(org.teiid.api.exception.query.QueryParserException) CommandContext(org.teiid.query.util.CommandContext) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) Evaluator(org.teiid.query.eval.Evaluator) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 2 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class DatabaseStore method getSchemaRecord.

public AbstractMetadataRecord getSchemaRecord(String name, Database.ResourceType type) {
    TransformationMetadata qmi = getTransformationMetadata();
    try {
        switch(type) {
            case TABLE:
                GroupSymbol gs = new GroupSymbol(name);
                ResolverUtil.resolveGroup(gs, qmi);
                Table t = (Table) gs.getMetadataID();
                if (t == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31245, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31245, name, getCurrentDatabase().getName(), getCurrentSchema().getName()));
                }
                return t;
            case PROCEDURE:
                StoredProcedureInfo sp = qmi.getStoredProcedureInfoForProcedure(name);
                if (sp == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31213, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31213, name, getCurrentSchema().getName(), getCurrentDatabase().getName()));
                }
                if (sp.getProcedureID() instanceof Procedure) {
                    return (Procedure) sp.getProcedureID();
                }
                return null;
            case COLUMN:
                Column c = qmi.getElementID(name);
                if (c == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31223, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31223, name));
                }
                return c;
            case DATABASE:
                return getCurrentDatabase();
            case SCHEMA:
                Schema schema = qmi.getModelID(name);
                if (schema == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31234, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31234, name, getCurrentDatabase().getName()));
                }
                return schema;
            case SERVER:
                Server server = getCurrentDatabase().getServer(name);
                if (server == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31220, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31220, name, getCurrentDatabase().getName()));
                }
                return server;
            case DATAWRAPPER:
                DataWrapper dw = getCurrentDatabase().getDataWrapper(name);
                if (dw == null) {
                    throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31247, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31247, name, getCurrentDatabase().getName()));
                }
                return dw;
            default:
                break;
        }
    } catch (TeiidComponentException e) {
        throw new MetadataException(e);
    } catch (QueryResolverException e) {
        throw new MetadataException(e);
    }
    return null;
}
Also used : QueryResolverException(org.teiid.api.exception.query.QueryResolverException) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 3 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class DDLStringVisitor method buildContraints.

private void buildContraints(Table table) {
    // $NON-NLS-1$
    addConstraints(table.getAccessPatterns(), "AP", ACCESSPATTERN);
    KeyRecord pk = table.getPrimaryKey();
    if (pk != null) {
        // $NON-NLS-1$
        addConstraint("PK", PRIMARY_KEY, pk, true);
    }
    addConstraints(table.getUniqueKeys(), UNIQUE, UNIQUE);
    addConstraints(table.getIndexes(), INDEX, INDEX);
    addConstraints(table.getFunctionBasedIndexes(), INDEX, INDEX);
    for (int i = 0; i < table.getForeignKeys().size(); i++) {
        ForeignKey key = table.getForeignKeys().get(i);
        // $NON-NLS-1$
        addConstraint("FK" + i, FOREIGN_KEY, key, false);
        append(SPACE).append(REFERENCES);
        if (key.getReferenceKey() != null) {
            if (key.getReferenceKey().getParent().getParent().equals(key.getParent().getParent())) {
                append(SPACE).append(new GroupSymbol(key.getReferenceKey().getParent().getName()));
            } else {
                append(SPACE).append(new GroupSymbol(key.getReferenceKey().getParent().getFullName()));
            }
        } else if (key.getReferenceTableName() != null) {
            append(SPACE).append(new GroupSymbol(key.getReferenceTableName()));
        }
        append(SPACE);
        addNames(key.getReferenceColumns());
        appendOptions(key);
    }
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 4 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestInsertImpl method helpExample.

public static org.teiid.query.sql.lang.Insert helpExample(String groupName) {
    GroupSymbol group = TestGroupImpl.helpExample(groupName);
    ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e1"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e2"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e3"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e4"));
    ArrayList<Constant> values = new ArrayList<Constant>();
    values.add(TestLiteralImpl.helpExample(1));
    values.add(TestLiteralImpl.helpExample(2));
    values.add(TestLiteralImpl.helpExample(3));
    values.add(TestLiteralImpl.helpExample(4));
    return new org.teiid.query.sql.lang.Insert(group, elements, values);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Insert(org.teiid.language.Insert)

Example 5 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestInsertImpl method helpExample2.

public static org.teiid.query.sql.lang.Insert helpExample2(String groupName) {
    GroupSymbol group = TestGroupImpl.helpExample(groupName);
    ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e1"));
    ArrayList<org.teiid.query.sql.symbol.Expression> values = new ArrayList<org.teiid.query.sql.symbol.Expression>();
    values.add(TestSearchedCaseExpressionImpl.helpExample());
    return new org.teiid.query.sql.lang.Insert(group, elements, values);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.language.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Insert(org.teiid.language.Insert)

Aggregations

GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)299 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)146 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)92 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)59 Expression (org.teiid.query.sql.symbol.Expression)52 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 Constant (org.teiid.query.sql.symbol.Constant)48 List (java.util.List)43 HashSet (java.util.HashSet)32 Query (org.teiid.query.sql.lang.Query)31 From (org.teiid.query.sql.lang.From)29 SymbolMap (org.teiid.query.sql.util.SymbolMap)29 Select (org.teiid.query.sql.lang.Select)26 Criteria (org.teiid.query.sql.lang.Criteria)22 TempMetadataID (org.teiid.query.metadata.TempMetadataID)21 LinkedList (java.util.LinkedList)20 Command (org.teiid.query.sql.lang.Command)20 Set (java.util.Set)17 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)17