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);
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations