Package adipe.translate.sql

Examples of adipe.translate.sql.ColumnNamesImpl


        ambiguous2  = schema.schemaTable("p");

        q2          = schema.schemaTable("xy");
        new_p       = schema.schemaTable("p");
        withAmbiguousColumnNames = schema3.schemaTable("withAmbiguousColumnNames");
        withAliases = new ColumnNamesImpl();
        withAliases.addColumn("alias_r", new SimpleColumn(AnyType.INSTANCE, "r"));

        scope1 = new ColumnScope(null);
        scope2 = new ColumnScope(scope1);
View Full Code Here


    @Test public void qualifiedGetFromShadowingTableFromOuter() throws AmbiguousNameException {
        assertThat(scope4.getIcNshdNwrapAmbInd("q.y")).isSameAs(q2.columnsMultimap().get("y").get(0));
    }

    @Test public void getFromShadowedTable() throws AmbiguousNameException {
        ColumnNamesImpl p = schema.schemaTable("p");
        ColumnNamesImpl q = schema.schemaTable("q");
        scope1 = new ColumnScope(null);
        scope1.addTable("shadow", p);
        scope2 = new ColumnScope(scope1);
        scope2.addTable("shadow", q);
        assertThat(scope2.getIcNshdNwrapAmbInd("b")).isSameAs(p.columnsMultimap().get("b").get(0));
View Full Code Here

        scope2.addTable("shadow", q);
        assertThat(scope2.getIcNshdNwrapAmbInd("b")).isSameAs(p.columnsMultimap().get("b").get(0));
    }

    @Test public void getFromShadowedTableFromOuter() throws AmbiguousNameException {
        ColumnNamesImpl p = schema.schemaTable("p");
        ColumnNamesImpl q = schema.schemaTable("q");
        scope1 = new ColumnScope(null);
        scope1.addTable("shadow", p);
        scope2 = new ColumnScope(scope1);
        scope2.addTable("shadow", q);
        scope3 = new ColumnScope(scope2);
View Full Code Here

        return makeState2(subquery, colNamesWr[0].asColumnIndexesLookup(), addQualifiedColumnNames(subquery.alias(), colNamesWr[0]));
    }

    private ColumnNamesImpl addQualifiedColumnNames(String tableName, ColumnNamesImpl withoutQualified) {
        ColumnNamesImpl named = new ColumnNamesImpl(withoutQualified);
        for (Entry<String, SimpleColumn> entry : withoutQualified.columnsMultimap().entries()) {
            named.addColumn(tableName+"."+entry.getKey(), entry.getValue());
        }
        return named;
    }
View Full Code Here

            throw new RuntimeException("JOIN specification missing");
        }

        boolean isInnerJoin = joinType == null || joinType.INNER() != null;

        ColumnNamesImpl named = new ColumnNamesImpl();
        named.addAll(r1.named().inner());
        named.addAll(r2.named().inner());

        if (! isInnerJoin) {
            r1.overwriteExpand();
            r2.overwriteExpand();
        }

        Proposition p = visitJoinSpecification(joinSpecification, columnNamesLookupForJoin2(r1, r2));

        // TODO move the check inside {@link Proposition} instead of matching like this
        boolean pIsEq;
        String pcode = p.code(columnIndexesForJoin2(r1, r2));
        Matcher eqMatcher = EQ_PATTERN.matcher(pcode);
        pIsEq = eqMatcher.matches();
        if (pIsEq) {
            // TODO refactor
            int index1 = Integer.parseInt(eqMatcher.group(1));
            int index2 = Integer.parseInt(eqMatcher.group(2));
            if (index1 > index2) {
                int tmp = index1;
                index1 = index2;
                index2 = tmp;
            }

            boolean bothColumnsFromSameOperand = (index1 > r1.relation().columns().size() || index2 <= r1.relation().columns().size());
            if (bothColumnsFromSameOperand) {
                pIsEq = false;
            } else if (isInnerJoin) {
                index2 = index2 - r1.relation().columns().size();

                SimpleColumn replacedColumn = r2.relation().columns().get(index2 - 1);
                SimpleColumn replacedBy = r1.relation().columns().get(index1 - 1);
                for (ColumnNamesImpl cibn : relationsFound.values()) {
                    // TODO improve time complexity
                    cibn.replace(replacedColumn, replacedBy);
                }
                named.replace(replacedColumn, replacedBy);
            }
        }

        if (checkContainsSubquery(p)) {
            throw new RuntimeException("not implemented (EXISTS in JOIN condition)");
View Full Code Here

        SimpleColumn column = columnScope().getIcNshdNwrapAmbInd(columnNameIc);

        String tableNameIc = TableScope.getTableNameIfQualifiedName(columnNameIc);
        if (tableNameIc != null) {
            String unqualifiedColumnNameIc = TableScope.getUnqualifiedColumnName(columnNameIc);
            ColumnNamesImpl table = tableScope.getIc(tableNameIc);
            List<SimpleColumn> cs = table.getIcNshdNwrapNambNindList(unqualifiedColumnNameIc);
            if (cs.size() == 0 /*|| cs.get(0).column() != column*/) {
                /* column must have been taken from a shadowed table */
                throw new IndexOutOfBoundsException(String.format("No column '%s' in scope", columnNameIc));
            }
        }
View Full Code Here

                formula = tv.visitQueryExpression(ctx.queryExpression());

                if (derivedColumnList != null) {
                    colNamesWr[0] = formula.renameColumns(derivedColumnList);
                } else {
                    colNamesWr[0] = new ColumnNamesImpl(formula.columns());
                }
                return formula.withAlias(newName);
            }

        };
View Full Code Here

            String columnName = columnNameList.get(i);
            Type columnType = typeList.get(i);
            c.put(columnName.toLowerCase(), new SimpleColumn(columnType, columnName));
        }

        return new ColumnNamesImpl(nameCaseSensitive, c);
    }
View Full Code Here

     * @return a formula for the table and its columns
     */
    public Relation instantiateTable(String nameInSchemaIc, String newName, List<String> derivedColumnList, ColumnNamesImpl[] colNamesWr)
        throws IndexOutOfBoundsException, AmbiguousNameException
    {
        ColumnNamesImpl table = schemaTable(nameInSchemaIc);
        if (derivedColumnList != null) {
            table = table.renameColumns(derivedColumnList);
        }
        colNamesWr[0] = table;
        String nameInSchemaCaseSensitive = table.nameInSchema();
        Term formula;
        if (instantiatedTables.contains(nameInSchemaIc)) {
            formula = Relation.refTableFormula(nameInSchemaCaseSensitive);
        } else {
            formula = Relation.relTableFormula(nameInSchemaCaseSensitive, table.size());
            instantiatedTables.add(nameInSchemaIc);
        }
        ColumnIndexesImpl c = table.asColumnIndexesLookup();
        return new Relation(namesRelations, newName, formula, c, c);
    }
View Full Code Here

     * Create a scope, embedded in outer
     * @param outer outer scope, null if none
     */
    ColumnScope(ColumnScope outer)
    {
        this(outer==null?new ColumnNamesImpl():outer.names.deeper());
    }
View Full Code Here

TOP

Related Classes of adipe.translate.sql.ColumnNamesImpl

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.