Package org.teiid.language

Examples of org.teiid.language.DerivedColumn


     */
    static int[] getNeededColumns(List<DerivedColumn> select, RuntimeMetadata metadata) throws TranslatorException {
        int[] cols = new int[select.size()];
        Iterator iter = select.iterator();
        for(int i=0; iter.hasNext(); i++) {
            DerivedColumn symbol = (DerivedColumn) iter.next();
            Expression expr = symbol.getExpression();
            if(expr instanceof ColumnReference) {
                Column element = ((ColumnReference)expr).getMetadataObject();
                cols[i] = element.getPosition();
            } else {
                throw new TranslatorException(YahooPlugin.Util.getString("YahooExecution.Invalid_select_symbol", expr)); //$NON-NLS-1$
View Full Code Here


    public TestSelectSymbolImpl(String name) {
        super(name);
    }

    public static DerivedColumn example(String symbolName, String alias) throws Exception {
        DerivedColumn selectSymbol = new DerivedColumn(alias, new ColumnReference(null, symbolName, null, DataTypeManager.DefaultDataClasses.INTEGER));
        return selectSymbol;
    }
View Full Code Here

    }
   
    public void testGetColumnDataTypes(){
        Class<?>[] expectedResults = new Class[2];
        List<DerivedColumn> symbols = new ArrayList<DerivedColumn>();
        symbols.add(new DerivedColumn("c1", new Literal("3", DataTypeManager.DefaultDataClasses.STRING)))//$NON-NLS-1$//$NON-NLS-2$
        expectedResults[0] = DataTypeManager.DefaultDataClasses.STRING;
        symbols.add(new DerivedColumn("c2", new Literal(new Integer(5), DataTypeManager.DefaultDataClasses.INTEGER)))//$NON-NLS-1$
        expectedResults[1] = DataTypeManager.DefaultDataClasses.INTEGER;
        Select query = new Select(symbols, false, null, null, null, null, null);
        Class<?>[] results = query.getColumnTypes()
        assertEquals( results[0], expectedResults[0]);
        assertEquals( results[1], expectedResults[1]);    
View Full Code Here

    }
   
    public static SetQuery example2() throws Exception {
        NamedTable group = new NamedTable("ted", null, null); //$NON-NLS-1$
        ColumnReference element = new ColumnReference(group, "nugent", null, String.class); //$NON-NLS-1$
        DerivedColumn symbol = new DerivedColumn(null,element);
        List symbols = new ArrayList();
        symbols.add(symbol);
        List items = new ArrayList();
        items.add(group);
       
        NamedTable group2 = new NamedTable("dave", null, null); //$NON-NLS-1$
        ColumnReference element2 = new ColumnReference(group2, "barry", null, String.class); //$NON-NLS-1$
        DerivedColumn symbol2 = new DerivedColumn(null, element2);
        List symbols2 = new ArrayList();
        symbols2.add(symbol2);
       
        List items2 = new ArrayList();
        items2.add(group2);
View Full Code Here

    selectSymbols = query.getDerivedColumns();
    selectSymbolCount = selectSymbols.size();
    Iterator<DerivedColumn> symbolIter = selectSymbols.iterator();
    int index = 0;
    while (symbolIter.hasNext()) {
      DerivedColumn symbol = symbolIter.next();
      // get the name in source
      Expression expression = symbol.getExpression();
      if (expression instanceof ColumnReference) {
        Column element = ((ColumnReference) expression).getMetadataObject();
        selectSymbolIndexToElement.put(index, element);
        String qualifiedName = element.getParent().getNameInSource() + ':' + element.getNameInSource();
        selectSymbolNameToIndex .put(qualifiedName, index);
        String nameInSource = element.getNameInSource();
        if (null == nameInSource || nameInSource.length() == 0) {
          exceptions.add(new TranslatorException("name in source is null or empty for column "+ symbol.toString()));
          continue;
        }
        if (nameInSource.equalsIgnoreCase("id")) {
          idIndex = index;
        }
View Full Code Here

        return new TranslationUtility(vdbName);       
    }

    public Column getElement(String groupName, String elementName, TranslationUtility transUtil) throws Exception {
        Select query = (Select) transUtil.parseCommand("SELECT " + elementName + " FROM " + groupName); //$NON-NLS-1$ //$NON-NLS-2$
        DerivedColumn symbol = query.getDerivedColumns().get(0);
        ColumnReference element = (ColumnReference) symbol.getExpression();
        return element.getMetadataObject();
    }
View Full Code Here

                iExp = translate((AggregateSymbol)symbol);
            } else if(symbol instanceof ExpressionSymbol) {
                iExp = translate(((ExpressionSymbol)symbol).getExpression());
            }

            DerivedColumn selectSymbol = new DerivedColumn(alias, iExp);
            translatedSymbols.add(selectSymbol);
        }
      List<TableReference> items = null;
      if (query.getFrom() != null) {
        List clauses = query.getFrom().getClauses();
View Full Code Here

    // ################ TEST ELEMENT METADATAID ######################
   
    public Column getElementID(String groupName, String elementName, TranslationUtility transUtil) {
        Select query = (Select) transUtil.parseCommand("SELECT " + elementName + " FROM " + groupName); //$NON-NLS-1$ //$NON-NLS-2$
        DerivedColumn symbol = query.getDerivedColumns().get(0);
        ColumnReference element = (ColumnReference) symbol.getExpression();
        return element.getMetadataObject();
    }
View Full Code Here

  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);
  }
View Full Code Here

    NamedTable group = (NamedTable)query.getProjectedQuery().getFrom().get(0);     
    AbstractMetadataRecord groupMD = group.getMetadataObject();
    TestCase.assertEquals(groupProps, groupMD.getProperties());
   
   
    DerivedColumn symbl = query.getProjectedQuery().getDerivedColumns().get(0);
    ColumnReference element = (ColumnReference)symbl.getExpression();
    Column elementMD = element.getMetadataObject();

    Properties elementProps = new Properties();
    elementProps.setProperty("customPosition", "11");//$NON-NLS-1$ //$NON-NLS-2$
   
    TestCase.assertEquals(0, elementMD.getLength());
    TestCase.assertEquals("Foo", elementMD.getDefaultValue()); //$NON-NLS-1$
    TestCase.assertEquals("TrimNulls", elementMD.getFormat()); //$NON-NLS-1$
    TestCase.assertEquals(String.class, elementMD.getJavaType());
    TestCase.assertEquals(null, elementMD.getMaximumValue());
    TestCase.assertEquals(null, elementMD.getMinimumValue());
    TestCase.assertEquals("http://www.w3.org/2001/XMLSchema#anySimpleType", elementMD.getBaseTypeID()); //$NON-NLS-1$
    TestCase.assertEquals("http://www.w3.org/2001/XMLSchema#string", elementMD.getPrimitiveTypeID()); //$NON-NLS-1$
    TestCase.assertEquals("http://www.w3.org/2001/XMLSchema#string", elementMD.getDatatypeID()); //$NON-NLS-1$
    TestCase.assertEquals("COLUMN1", elementMD.getNameInSource()); //$NON-NLS-1$
    TestCase.assertEquals("STR", elementMD.getNativeType()); //$NON-NLS-1$
    TestCase.assertEquals(NullType.Nullable, elementMD.getNullType());
    TestCase.assertEquals(0, elementMD.getPosition());
    TestCase.assertEquals(0, elementMD.getPrecision());
    TestCase.assertEquals(0, elementMD.getScale());
    TestCase.assertEquals(SearchType.Searchable, elementMD.getSearchType());
    TestCase.assertEquals(false, elementMD.isAutoIncremented());
    TestCase.assertEquals(true, elementMD.isCaseSensitive());
    TestCase.assertEquals(elementProps, elementMD.getProperties());
   
   
    DerivedColumn symbl2 = query.getProjectedQuery().getDerivedColumns().get(1);
    ColumnReference element2 = (ColumnReference)symbl2.getExpression();
    Column elementMD2 = element2.getMetadataObject();

    Properties elementProps2 = new Properties();
    elementProps2.setProperty("customPosition", "12");//$NON-NLS-1$ //$NON-NLS-2$
   
View Full Code Here

TOP

Related Classes of org.teiid.language.DerivedColumn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.