/** * Helper method for getting runtime {@link org.teiid.connector.metadata.runtime.Element} from a * {@link org.teiid.language.DerivedColumn}. * @param symbol Input ISelectSymbol * @return Element returned metadata runtime Element */ private Column getElementFromSymbol(DerivedColumn symbol) { ColumnReference expr = (ColumnReference) symbol.getExpression(); return expr.getMetadataObject(); }
public void visit(DerivedColumn obj) { visitNode(obj.getExpression()); }
@Override public List<?> translate(LanguageObject obj, ExecutionContext context) { if (obj instanceof DerivedColumn) { DerivedColumn selectSymbol = (DerivedColumn)obj; if (selectSymbol.getExpression().getType() == TypeFacility.RUNTIME_TYPES.XML) { if (selectSymbol.getAlias() == null) { return Arrays.asList("XMLSERIALIZE(", selectSymbol.getExpression(), " AS CLOB)"); //$NON-NLS-1$//$NON-NLS-2$ } //we're assuming that alias quoting shouldn't be needed return Arrays.asList("XMLSERIALIZE(", selectSymbol.getExpression(), " AS CLOB) AS ", selectSymbol.getAlias()); //$NON-NLS-1$//$NON-NLS-2$ } } return super.translate(obj, context); }
public void visit(DerivedColumn obj) { append(obj.getExpression()); if (obj.getAlias() != null) { buffer.append(Tokens.SPACE) .append(AS) .append(Tokens.SPACE) .append(obj.getAlias()); } }
private void addSelectSymbols(StringBuilder result) { for (int i = 0; i < selectSymbols.size(); i++) { DerivedColumn symbol = selectSymbols.get(i); if (i > 0) { result.append(", "); //$NON-NLS-1$ } Expression expression = symbol.getExpression(); if (expression instanceof ColumnReference) { appendColumnReference(result, (ColumnReference) expression); } else if (expression instanceof AggregateFunction) { AggregateFunction af = (AggregateFunction)expression; appendAggregateFunction(result, af); } else { throw new AssertionError("Unknown select symbol type" + symbol); //$NON-NLS-1$ } } }
@Override public void visit(DerivedColumn obj) { visitNode(obj.getExpression()); createProjectedColumn(true); }
@Override public List<?> translateCommand(Command command, ExecutionContext context) { if (command instanceof Select) { Select select = (Select)command; if (select.getFrom() == null || select.getFrom().isEmpty()) { List<Object> result = new ArrayList<Object>(); result.add("VALUES("); //$NON-NLS-1$ for (int i = 0; i < select.getDerivedColumns().size(); i++) { DerivedColumn dc = select.getDerivedColumns().get(i); if (i != 0) { result.add(", "); //$NON-NLS-1$ } result.add(dc.getExpression()); } result.add(")"); //$NON-NLS-1$ return result; } } return super.translateCommand(command, context); }
@Override public List<?> translate(LanguageObject obj, ExecutionContext context) { if (obj instanceof DerivedColumn) { DerivedColumn derived = (DerivedColumn)obj; if (derived.isProjected() && derived.getExpression() instanceof ColumnReference) { ColumnReference elem = (ColumnReference)derived.getExpression(); if (elem.getMetadataObject() != null) { String nativeType = elem.getMetadataObject().getNativeType(); if (nativeType != null && TypeFacility.RUNTIME_TYPES.STRING.equals(elem.getType()) && PIMetadataProcessor.guidPattern.matcher(nativeType).find()) { return Arrays.asList("cast(", elem, " as String)"); //$NON-NLS-1$ //$NON-NLS-2$ } } } } return super.translate(obj, context); }
@Override public Class<?> getType() { return query.getProjectedQuery().getDerivedColumns().get(0).getExpression().getType(); }
/** * Get the column types of the output columns for this query * @return a Class[] containing the column names * @since 4.3 */ public Class<?>[] getColumnTypes() { List<DerivedColumn> selectSymbols = getProjectedQuery().getDerivedColumns(); Class<?>[] columnTypes = new Class[selectSymbols.size()]; int symbolIndex = 0; for (DerivedColumn column : selectSymbols) { columnTypes[symbolIndex++] = column.getExpression().getType(); } return columnTypes; }
@Override public List<?> translateCommand(Command command, ExecutionContext context) { if (command instanceof Select) { Select select = (Select)command; if (select.getFrom() == null || select.getFrom().isEmpty()) { List<Object> result = new ArrayList<Object>(); result.add("VALUES("); //$NON-NLS-1$ for (int i = 0; i < select.getDerivedColumns().size(); i++) { DerivedColumn dc = select.getDerivedColumns().get(i); if (i != 0) { result.add(", "); //$NON-NLS-1$ } result.add(dc.getExpression()); } result.add(")"); //$NON-NLS-1$ return result; } } return super.translateCommand(command, context); }
@Override public void visit(DerivedColumn obj) { if (obj.getExpression() instanceof ColumnReference) { Column column = ((ColumnReference)obj.getExpression()).getMetadataObject(); String joinColumn = column.getProperty(ODataMetadataProcessor.JOIN_COLUMN, false); if (joinColumn != null && Boolean.valueOf(joinColumn)) { this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17006, column.getName()))); } this.selectColumns.add(column); } else if (obj.getExpression() instanceof AggregateFunction) { AggregateFunction func = (AggregateFunction)obj.getExpression(); if (func.getName().equalsIgnoreCase("COUNT")) { //$NON-NLS-1$ this.count = true; } else { this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17007, func.getName()))); } } else { this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17008))); } }
private void addCast(String nativeType, DerivedColumn dc) { if (nativeType != null) { Function cast = ConvertModifier.createConvertFunction(getLanguageFactory(), dc.getExpression(), nativeType); cast.setName("cast"); //$NON-NLS-1$ dc.setExpression(cast); } else { dc.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), dc.getExpression(), TypeFacility.getDataTypeName(dc.getExpression().getType()))); } }
public ODataQueryExecution(ODataExecutionFactory translator, QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, WSConnection connection) throws TranslatorException { super(translator, executionContext, metadata, connection); this.visitor = new ODataSQLVisitor(this.translator, metadata); this.visitor.visitNode(command); if (command instanceof Select) { Select select = (Select)command; if (select.getGroupBy() == null && select.getDerivedColumns().get(0).getExpression() instanceof AggregateFunction) { this.isCount = true; } } if (!this.visitor.exceptions.isEmpty()) { throw visitor.exceptions.get(0); } this.expectedColumnTypes = command.getColumnTypes(); }
@Override public void visit(SetQuery obj) { for (int i = 0; i < obj.getColumnNames().length; i++) { DerivedColumn leftDerivedColumn = obj.getLeftQuery().getProjectedQuery().getDerivedColumns().get(i); boolean left_i18n = OracleExecutionFactory.this.isNonAscii(leftDerivedColumn.getExpression()); DerivedColumn rightDerivedColumn = obj.getRightQuery().getProjectedQuery().getDerivedColumns().get(i); boolean right_i18n = OracleExecutionFactory.this.isNonAscii(rightDerivedColumn.getExpression()); if (left_i18n ^ right_i18n) { if (!left_i18n) { leftDerivedColumn.setExpression(toNChar(leftDerivedColumn.getExpression())); } else if (!right_i18n) { rightDerivedColumn.setExpression(toNChar(rightDerivedColumn.getExpression())); } } } super.visit(obj); }
@Override public List<?> translateCommand(Command command, ExecutionContext context) { if (!supportsLiteralOnlyWithGrouping() && (command instanceof Select)) { Select select = (Select)command; if (select.getGroupBy() != null && select.getDerivedColumns().size() == 1) { DerivedColumn dc = select.getDerivedColumns().get(0); if (dc.getExpression() instanceof Literal) { dc.setExpression(select.getGroupBy().getElements().get(0)); } } } return super.translateCommand(command, context); }
public void testGetExpression() throws Exception { assertNotNull(example("testName", null).getExpression()); //$NON-NLS-1$ }
@Override public List<?> translate(LanguageObject obj, ExecutionContext context) { //DB2 doesn't support cross join convertCrossJoinToInner(obj, getLanguageFactory()); //DB2 needs projected nulls wrapped in casts if (obj instanceof DerivedColumn) { DerivedColumn selectSymbol = (DerivedColumn)obj; if (selectSymbol.getExpression() instanceof Literal) { Literal literal = (Literal)selectSymbol.getExpression(); if (literal.getValue() == null) { String type = TypeFacility.RUNTIME_NAMES.INTEGER; if (literal.getType() != TypeFacility.RUNTIME_TYPES.NULL) { type = TypeFacility.getDataTypeName(literal.getType()); } selectSymbol.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), literal, type)); } } } return super.translate(obj, context); }
public void testGetType() throws Exception { Select query = TstLanguageBridgeFactory.factory.translate(TestQueryImpl.helpExample(true)); Class<?> firstSymbolType = query.getDerivedColumns().get(0).getExpression().getType(); assertEquals("Got incorrect type", firstSymbolType, example().getType()); //$NON-NLS-1$ }
@Override public List<?> translateCommand(Command command, ExecutionContext context) { if (command instanceof SetQuery) { SetQuery set = (SetQuery)command; if (!set.isAll()) { //distinct is not supported, convert to an inline view and add distinct Select s = new Select(); s.setDistinct(true); s.setDerivedColumns(new ArrayList<DerivedColumn>()); s.setOrderBy(set.getOrderBy()); for (DerivedColumn dc : set.getProjectedQuery().getDerivedColumns()) { Assertion.assertTrue(dc.getAlias() != null); //it's expected that the columns will be aliases ColumnReference cr = new ColumnReference(null, dc.getAlias(), null, dc.getExpression().getType()); s.getDerivedColumns().add(new DerivedColumn(null, cr)); } set.setOrderBy(null); s.setLimit(set.getLimit()); set.setLimit(null); set.setAll(true); s.setFrom(Arrays.asList((TableReference)new DerivedTable(set, "x"))); //$NON-NLS-1$ return Arrays.asList(s); } } return super.translateCommand(command, context); }