Search in sources :

Example 61 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class RelOptUtil method pushDownJoinConditions.

/**
 * Pushes down expressions in "equal" join condition.
 *
 * <p>For example, given
 * "emp JOIN dept ON emp.deptno + 1 = dept.deptno", adds a project above
 * "emp" that computes the expression
 * "emp.deptno + 1". The resulting join condition is a simple combination
 * of AND, equals, and input fields, plus the remaining non-equal conditions.
 *
 * @param originalJoin Join whose condition is to be pushed down
 * @param relBuilder Factory to create project operator
 */
public static RelNode pushDownJoinConditions(Join originalJoin, RelBuilder relBuilder) {
    RexNode joinCond = originalJoin.getCondition();
    final JoinRelType joinType = originalJoin.getJoinType();
    final List<RexNode> extraLeftExprs = new ArrayList<>();
    final List<RexNode> extraRightExprs = new ArrayList<>();
    final int leftCount = originalJoin.getLeft().getRowType().getFieldCount();
    final int rightCount = originalJoin.getRight().getRowType().getFieldCount();
    // yet.
    if (!containsGet(joinCond) && RexUtil.SubQueryFinder.find(joinCond) == null) {
        joinCond = pushDownEqualJoinConditions(joinCond, leftCount, rightCount, extraLeftExprs, extraRightExprs);
    }
    relBuilder.push(originalJoin.getLeft());
    if (!extraLeftExprs.isEmpty()) {
        final List<RelDataTypeField> fields = relBuilder.peek().getRowType().getFieldList();
        final List<Pair<RexNode, String>> pairs = new AbstractList<Pair<RexNode, String>>() {

            public int size() {
                return leftCount + extraLeftExprs.size();
            }

            public Pair<RexNode, String> get(int index) {
                if (index < leftCount) {
                    RelDataTypeField field = fields.get(index);
                    return Pair.<RexNode, String>of(new RexInputRef(index, field.getType()), field.getName());
                } else {
                    return Pair.of(extraLeftExprs.get(index - leftCount), null);
                }
            }
        };
        relBuilder.project(Pair.left(pairs), Pair.right(pairs));
    }
    relBuilder.push(originalJoin.getRight());
    if (!extraRightExprs.isEmpty()) {
        final List<RelDataTypeField> fields = relBuilder.peek().getRowType().getFieldList();
        final int newLeftCount = leftCount + extraLeftExprs.size();
        final List<Pair<RexNode, String>> pairs = new AbstractList<Pair<RexNode, String>>() {

            public int size() {
                return rightCount + extraRightExprs.size();
            }

            public Pair<RexNode, String> get(int index) {
                if (index < rightCount) {
                    RelDataTypeField field = fields.get(index);
                    return Pair.<RexNode, String>of(new RexInputRef(index, field.getType()), field.getName());
                } else {
                    return Pair.of(RexUtil.shift(extraRightExprs.get(index - rightCount), -newLeftCount), null);
                }
            }
        };
        relBuilder.project(Pair.left(pairs), Pair.right(pairs));
    }
    final RelNode right = relBuilder.build();
    final RelNode left = relBuilder.build();
    relBuilder.push(originalJoin.copy(originalJoin.getTraitSet(), joinCond, left, right, joinType, originalJoin.isSemiJoinDone()));
    if (!extraLeftExprs.isEmpty() || !extraRightExprs.isEmpty()) {
        Mappings.TargetMapping mapping = Mappings.createShiftMapping(leftCount + extraLeftExprs.size() + rightCount + extraRightExprs.size(), 0, 0, leftCount, leftCount, leftCount + extraLeftExprs.size(), rightCount);
        relBuilder.project(relBuilder.fields(mapping.inverse()));
    }
    return relBuilder.build();
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) JoinRelType(org.apache.calcite.rel.core.JoinRelType) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelNode(org.apache.calcite.rel.RelNode) Mappings(org.apache.calcite.util.mapping.Mappings) RexInputRef(org.apache.calcite.rex.RexInputRef) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Example 62 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class RelOptUtil method createRename.

// to be removed before 2.0
@Deprecated
public static RelNode createRename(RelNode rel, List<String> fieldNames) {
    final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
    assert fieldNames.size() == fields.size();
    final List<RexNode> refs = new AbstractList<RexNode>() {

        public int size() {
            return fields.size();
        }

        public RexNode get(int index) {
            return RexInputRef.of(index, fields);
        }
    };
    final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
    return relBuilder.push(rel).projectNamed(refs, fieldNames, false).build();
}
Also used : AbstractList(java.util.AbstractList) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelBuilder(org.apache.calcite.tools.RelBuilder) RexNode(org.apache.calcite.rex.RexNode)

Example 63 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class RelOptTableImpl method columnStrategies.

/**
 * Helper for {@link #getColumnStrategies()}.
 */
public static List<ColumnStrategy> columnStrategies(final RelOptTable table) {
    final int fieldCount = table.getRowType().getFieldCount();
    final InitializerExpressionFactory ief = Util.first(table.unwrap(InitializerExpressionFactory.class), NullInitializerExpressionFactory.INSTANCE);
    return new AbstractList<ColumnStrategy>() {

        public int size() {
            return fieldCount;
        }

        public ColumnStrategy get(int index) {
            return ief.generationStrategy(table, index);
        }
    };
}
Also used : AbstractList(java.util.AbstractList) NullInitializerExpressionFactory(org.apache.calcite.sql2rel.NullInitializerExpressionFactory) InitializerExpressionFactory(org.apache.calcite.sql2rel.InitializerExpressionFactory) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 64 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class RelDataTypeFactoryImpl method leastRestrictiveStructuredType.

protected RelDataType leastRestrictiveStructuredType(final List<RelDataType> types) {
    final RelDataType type0 = types.get(0);
    final int fieldCount = type0.getFieldCount();
    // precheck that all types are structs with same number of fields
    for (RelDataType type : types) {
        if (!type.isStruct()) {
            return null;
        }
        if (type.getFieldList().size() != fieldCount) {
            return null;
        }
    }
    // recursively compute column-wise least restrictive
    final Builder builder = builder();
    for (int j = 0; j < fieldCount; ++j) {
        // REVIEW jvs 22-Jan-2004:  Always use the field name from the
        // first type?
        final int k = j;
        builder.add(type0.getFieldList().get(j).getName(), leastRestrictive(new AbstractList<RelDataType>() {

            public RelDataType get(int index) {
                return types.get(index).getFieldList().get(k).getType();
            }

            public int size() {
                return types.size();
            }
        }));
    }
    return builder.build();
}
Also used : AbstractList(java.util.AbstractList) CacheBuilder(com.google.common.cache.CacheBuilder)

Example 65 with AbstractList

use of java.util.AbstractList in project calcite by apache.

the class RexLiteral method printAsJava.

/**
 * Prints a value as a Java string. The value must be consistent with the
 * type, as per {@link #valueMatchesType}.
 *
 * <p>Typical return values:
 *
 * <ul>
 * <li>true</li>
 * <li>null</li>
 * <li>"Hello, world!"</li>
 * <li>1.25</li>
 * <li>1234ABCD</li>
 * </ul>
 *
 * @param value    Value
 * @param pw       Writer to write to
 * @param typeName Type family
 */
private static void printAsJava(Comparable value, PrintWriter pw, SqlTypeName typeName, boolean java) {
    switch(typeName) {
        case CHAR:
            NlsString nlsString = (NlsString) value;
            if (java) {
                Util.printJavaString(pw, nlsString.getValue(), true);
            } else {
                boolean includeCharset = (nlsString.getCharsetName() != null) && !nlsString.getCharsetName().equals(SaffronProperties.INSTANCE.defaultCharset().get());
                pw.print(nlsString.asSql(includeCharset, false));
            }
            break;
        case BOOLEAN:
            assert value instanceof Boolean;
            pw.print(((Boolean) value).booleanValue());
            break;
        case DECIMAL:
            assert value instanceof BigDecimal;
            pw.print(value.toString());
            break;
        case DOUBLE:
            assert value instanceof BigDecimal;
            pw.print(Util.toScientificNotation((BigDecimal) value));
            break;
        case BIGINT:
            assert value instanceof BigDecimal;
            pw.print(((BigDecimal) value).longValue());
            pw.print('L');
            break;
        case BINARY:
            assert value instanceof ByteString;
            pw.print("X'");
            pw.print(((ByteString) value).toString(16));
            pw.print("'");
            break;
        case NULL:
            assert value == null;
            pw.print("null");
            break;
        case SYMBOL:
            assert value instanceof Enum;
            pw.print("FLAG(");
            pw.print(value);
            pw.print(")");
            break;
        case DATE:
            assert value instanceof DateString;
            pw.print(value);
            break;
        case TIME:
            assert value instanceof TimeString;
            pw.print(value);
            break;
        case TIME_WITH_LOCAL_TIME_ZONE:
            assert value instanceof TimeString;
            pw.print(value);
            break;
        case TIMESTAMP:
            assert value instanceof TimestampString;
            pw.print(value);
            break;
        case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
            assert value instanceof TimestampString;
            pw.print(value);
            break;
        case INTERVAL_YEAR:
        case INTERVAL_YEAR_MONTH:
        case INTERVAL_MONTH:
        case INTERVAL_DAY:
        case INTERVAL_DAY_HOUR:
        case INTERVAL_DAY_MINUTE:
        case INTERVAL_DAY_SECOND:
        case INTERVAL_HOUR:
        case INTERVAL_HOUR_MINUTE:
        case INTERVAL_HOUR_SECOND:
        case INTERVAL_MINUTE:
        case INTERVAL_MINUTE_SECOND:
        case INTERVAL_SECOND:
            if (value instanceof BigDecimal) {
                pw.print(value.toString());
            } else {
                assert value == null;
                pw.print("null");
            }
            break;
        case MULTISET:
        case ROW:
            @SuppressWarnings("unchecked") final List<RexLiteral> list = (List) value;
            pw.print(new AbstractList<String>() {

                public String get(int index) {
                    return list.get(index).digest;
                }

                public int size() {
                    return list.size();
                }
            });
            break;
        default:
            assert valueMatchesType(value, typeName, true);
            throw Util.needToImplement(typeName);
    }
}
Also used : TimeString(org.apache.calcite.util.TimeString) ByteString(org.apache.calcite.avatica.util.ByteString) TimeString(org.apache.calcite.util.TimeString) DateString(org.apache.calcite.util.DateString) NlsString(org.apache.calcite.util.NlsString) ByteString(org.apache.calcite.avatica.util.ByteString) TimestampString(org.apache.calcite.util.TimestampString) BigDecimal(java.math.BigDecimal) DateString(org.apache.calcite.util.DateString) NlsString(org.apache.calcite.util.NlsString) AbstractList(java.util.AbstractList) ImmutableList(com.google.common.collect.ImmutableList) CompositeList(org.apache.calcite.util.CompositeList) List(java.util.List) TimestampString(org.apache.calcite.util.TimestampString)

Aggregations

AbstractList (java.util.AbstractList)76 ArrayList (java.util.ArrayList)30 List (java.util.List)17 HashMap (java.util.HashMap)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 QName (org.alfresco.service.namespace.QName)9 UserInfo (org.alfresco.rest.api.model.UserInfo)8 FileInfo (org.alfresco.service.cmr.model.FileInfo)8 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)7 RexNode (org.apache.calcite.rex.RexNode)7 Collection (java.util.Collection)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 Iterator (java.util.Iterator)6 Paging (org.alfresco.rest.framework.resource.parameters.Paging)6 IOException (java.io.IOException)5 Set (java.util.Set)5 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)5 Test (org.junit.Test)5 ListIterator (java.util.ListIterator)4 RandomAccess (java.util.RandomAccess)4