use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class MetaDataProcessor method createProjectedSymbolMetadata.
private Map<Integer, Object>[] createProjectedSymbolMetadata(Command originalCommand) throws TeiidComponentException {
Map<Integer, Object>[] columnMetadata;
// Allow command to use temporary metadata
TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata();
if (tempMetadata != null && tempMetadata.getData().size() > 0) {
TempMetadataAdapter tempFacade = new TempMetadataAdapter(this.metadata, tempMetadata);
this.metadata = tempFacade;
}
List<Expression> projectedSymbols = originalCommand.getProjectedSymbols();
columnMetadata = new Map[projectedSymbols.size()];
Iterator<Expression> symbolIter = projectedSymbols.iterator();
for (int i = 0; symbolIter.hasNext(); i++) {
Expression symbol = symbolIter.next();
String shortColumnName = Symbol.getShortName(Symbol.getOutputName(symbol));
if (symbol instanceof AliasSymbol) {
symbol = ((AliasSymbol) symbol).getSymbol();
}
try {
columnMetadata[i] = createColumnMetadata(shortColumnName, symbol);
} catch (QueryMetadataException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30559, e);
}
}
return columnMetadata;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public org.teiid.language.OrderBy translate(OrderBy orderBy, boolean set) {
if (orderBy == null) {
return null;
}
List<OrderByItem> items = orderBy.getOrderByItems();
List<SortSpecification> translatedItems = new ArrayList<SortSpecification>();
for (int i = 0; i < items.size(); i++) {
Expression symbol = items.get(i).getSymbol();
Ordering direction = items.get(i).isAscending() ? Ordering.ASC : Ordering.DESC;
SortSpecification orderByItem = null;
if (!set && (items.get(i).isUnrelated() || symbol instanceof ElementSymbol)) {
orderByItem = new SortSpecification(direction, translate(symbol));
} else {
orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol) symbol).getOutputName()), null, symbol.getType()));
}
orderByItem.setNullOrdering(items.get(i).getNullOrdering());
translatedItems.add(orderByItem);
}
return new org.teiid.language.OrderBy(translatedItems);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
/* Query */
Select translate(Query query) {
With with = translate(query.getWith());
List<Expression> symbols = query.getSelect().getSymbols();
List<DerivedColumn> translatedSymbols = new ArrayList<DerivedColumn>(symbols.size());
for (Iterator<Expression> i = symbols.iterator(); i.hasNext(); ) {
Expression symbol = i.next();
String alias = null;
if (symbol instanceof AliasSymbol) {
alias = ((AliasSymbol) symbol).getOutputName();
symbol = ((AliasSymbol) symbol).getSymbol();
}
org.teiid.language.Expression iExp = translate(symbol);
DerivedColumn selectSymbol = new DerivedColumn(alias, iExp);
translatedSymbols.add(selectSymbol);
}
List<TableReference> items = null;
if (query.getFrom() != null) {
List<FromClause> clauses = query.getFrom().getClauses();
items = new ArrayList<TableReference>(clauses.size());
for (Iterator<FromClause> i = clauses.iterator(); i.hasNext(); ) {
items.add(translate(i.next()));
}
}
Select q = new Select(translatedSymbols, query.getSelect().isDistinct(), items, translate(query.getCriteria()), translate(query.getGroupBy()), translate(query.getHaving()), translate(query.getOrderBy(), false));
q.setLimit(translate(query.getLimit()));
q.setWith(with);
return q;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
org.teiid.language.Expression translate(Function function) {
Expression[] args = function.getArgs();
List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>(args.length);
for (int i = 0; i < args.length; i++) {
params.add(translate(args[i]));
}
String name = function.getName();
if (function.getFunctionDescriptor() != null) {
name = function.getFunctionDescriptor().getName();
if (!supportsConcat2 && function.getFunctionDescriptor().getMethod().getParent() == null && name.equalsIgnoreCase(SourceSystemFunctions.CONCAT2)) {
Expression[] newArgs = new Expression[args.length];
boolean useCase = true;
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Constant) {
newArgs[i] = args[i];
useCase = false;
} else {
// $NON-NLS-1$
Function f = new Function(SourceSystemFunctions.IFNULL, new Expression[] { args[i], new Constant("") });
newArgs[i] = f;
f.setType(args[i].getType());
FunctionDescriptor descriptor = metadataFactory.getMetadata().getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL, new Class[] { args[i].getType(), DataTypeManager.DefaultDataClasses.STRING });
f.setFunctionDescriptor(descriptor);
}
}
Function concat = new Function(SourceSystemFunctions.CONCAT, newArgs);
concat.setType(DataTypeManager.DefaultDataClasses.STRING);
if (!useCase) {
return translate(concat);
}
FunctionDescriptor descriptor = metadataFactory.getMetadata().getFunctionLibrary().findFunction(SourceSystemFunctions.CONCAT, new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
concat.setFunctionDescriptor(descriptor);
List<CompoundCriteria> when = Arrays.asList(new CompoundCriteria(CompoundCriteria.AND, new IsNullCriteria(args[0]), new IsNullCriteria(args[1])));
Constant nullConstant = new Constant(null, DataTypeManager.DefaultDataClasses.STRING);
List<Constant> then = Arrays.asList(nullConstant);
SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then);
caseExpr.setElseExpression(concat);
caseExpr.setType(DataTypeManager.DefaultDataClasses.STRING);
return translate(caseExpr);
}
// check for translator pushdown functions, and use the name in source if possible
if (function.getFunctionDescriptor().getMethod().getNameInSource() != null && (CoreConstants.SYSTEM_MODEL.equals(function.getFunctionDescriptor().getSchema()) || (function.getFunctionDescriptor().getMethod().getParent() != null && function.getFunctionDescriptor().getMethod().getParent().isPhysical()))) {
name = function.getFunctionDescriptor().getMethod().getNameInSource();
}
} else {
name = Symbol.getShortName(name);
}
// if there is any ambiguity in the function name it will be up to the translator logic to check the
// metadata
org.teiid.language.Function result = new org.teiid.language.Function(name, params, function.getType());
if (function.getFunctionDescriptor() != null) {
result.setMetadataObject(function.getFunctionDescriptor().getMethod());
}
return result;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
org.teiid.language.WindowFunction translate(WindowFunction windowFunction) {
org.teiid.language.WindowFunction result = new org.teiid.language.WindowFunction();
result.setFunction(translate(windowFunction.getFunction()));
WindowSpecification ws = new WindowSpecification();
ws.setOrderBy(translate(windowFunction.getWindowSpecification().getOrderBy(), false));
List<Expression> partition = windowFunction.getWindowSpecification().getPartition();
if (partition != null) {
ArrayList<org.teiid.language.Expression> partitionList = translateExpressionList(partition);
ws.setPartition(partitionList);
}
result.setWindowSpecification(ws);
return result;
}
Aggregations