use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class ODataSQLBuilder method selectWithEntityKey.
// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
Table table = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
resource.addAllColumns(false);
this.context = resource;
Query query = this.context.buildQuery();
processExpand(expand, resource, query, 1);
Criteria criteria = null;
KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
for (Column c : pk.getColumns()) {
Property prop = entity.getProperty(c.getName());
Constant right = null;
if (prop != null) {
right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
} else {
Object value = generatedKeys.get(c.getName());
if (value == null) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
}
right = new Constant(value);
}
ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
if (criteria == null) {
criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
} else {
CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
}
}
query.setCriteria(criteria);
return query;
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class DocumentNode method build.
public static DocumentNode build(DocumentNode resource, EdmEntityType type, List<UriParameter> keyPredicates, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidException {
Table table = findTable(type, metadata);
GroupSymbol gs = null;
if (useAlias) {
gs = new GroupSymbol(nameGenerator.getNextGroup(), table.getFullName());
} else {
gs = new GroupSymbol(table.getFullName());
}
resource.setTable(table);
resource.setGroupSymbol(gs);
resource.setEdmEntityType(type);
resource.setKeyPredicates(keyPredicates);
resource.setFromClause(new UnaryFromClause(gs));
if (keyPredicates != null && !keyPredicates.isEmpty()) {
Criteria criteria = DocumentNode.buildEntityKeyCriteria(resource, uriInfo, metadata, odata, nameGenerator, parseService);
resource.setCriteria(criteria);
}
return resource;
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(UriResourceIt info) {
if (info.getType() instanceof SingletonPrimitiveType) {
org.teiid.query.sql.symbol.Expression ex = null;
if (this.ctxQuery.getIterator() == null) {
String group = this.nameGenerator.getNextGroup();
GroupSymbol groupSymbol = new GroupSymbol(group);
StoredProcedure procedure = new StoredProcedure();
procedure.setProcedureName("arrayiterate");
// the projected should only be the collection property at this point
// we may need more checks here to ensure that is valid
Collection<ProjectedColumn> values = this.ctxQuery.getProjectedColumns().values();
Assertion.assertTrue(values.size() == 1);
ProjectedColumn projectedColumn = values.iterator().next();
ElementSymbol projectedEs = (ElementSymbol) projectedColumn.getExpression();
List<SPParameter> params = new ArrayList<SPParameter>();
SPParameter param = new SPParameter(1, SPParameter.IN, "val");
param.setExpression(projectedEs);
params.add(param);
procedure.setParameter(param);
SubqueryFromClause fromClause = new SubqueryFromClause(group, procedure);
fromClause.setLateral(true);
ElementSymbol es = new ElementSymbol("col", groupSymbol);
String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
Function castFunction = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
DocumentNode itResource = new DocumentNode();
org.teiid.query.sql.symbol.Expression clone = (org.teiid.query.sql.symbol.Expression) castFunction.clone();
AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, clone);
AliasSymbol expression = new AliasSymbol(projectedEs.getShortName(), symbol);
itResource.setFromClause(fromClause);
itResource.setGroupSymbol(groupSymbol);
itResource.addProjectedColumn(expression, info.getType(), projectedColumn.getProperty(), true);
this.ctxQuery.getProjectedColumns().remove(projectedColumn.getExpression());
this.ctxQuery.setIterator(itResource);
ex = castFunction;
} else {
GroupSymbol groupSymbol = this.ctxQuery.getIterator().getGroupSymbol();
ElementSymbol es = new ElementSymbol("col", groupSymbol);
String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
ex = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
}
this.stack.push(ex);
} else {
boolean ex = true;
if (this.ctxQuery instanceof ExpandDocumentNode) {
ExpandDocumentNode node = (ExpandDocumentNode) this.ctxQuery;
DocumentNode parent = node.getCollectionContext();
if (parent != null) {
this.ctxExpression = parent;
ex = false;
}
}
if (ex) {
throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16010, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16010)));
}
}
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(UriResourceLambdaVariable resource) {
try {
if (this.ctxLambda == null) {
DocumentNode lambda = DocumentNode.build((EdmEntityType) resource.getType(), null, this.metadata, this.odata, this.nameGenerator, false, this.uriInfo, this.parseService);
lambda.setGroupSymbol(new GroupSymbol(resource.getVariableName(), lambda.getFullName()));
this.ctxLambda = lambda;
}
this.ctxExpression = ctxLambda;
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.
the class ComplexDocumentNode method buildComplexDocumentNode.
public static ComplexDocumentNode buildComplexDocumentNode(EdmOperation edmOperation, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidProcessingException {
ComplexDocumentNode resource = new ComplexDocumentNode();
FullQualifiedName fqn = edmOperation.getFullQualifiedName();
String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.') + 1);
Schema schema = metadata.getSchema(withoutVDB);
Procedure procedure = schema.getProcedure(edmOperation.getName());
StoredProcedure storedQuery = new StoredProcedure();
// $NON-NLS-1$
storedQuery.setProcedureName(procedure.getFullName());
for (int i = 0; i < procedure.getParameters().size(); i++) {
storedQuery.setParameter(new SPParameter(i + 1, new Reference(i)));
}
String group = nameGenerator.getNextGroup();
// $NON-NLS-1$
SubqueryFromClause sfc = new SubqueryFromClause(group, storedQuery);
resource.setGroupSymbol(new GroupSymbol(group));
resource.setFromClause(sfc);
resource.procedure = procedure;
return resource;
}
Aggregations