public List<SqlMoniker> getAllSchemaObjectNames(List<String> names) { List<SqlMoniker> result; switch (names.size()) { case 0: // looking for schema names result = new ArrayList<SqlMoniker>(); for (MockSchema schema : schemas.values()) { result.add(new SqlMonikerImpl(schema.name, SqlMonikerType.Schema)); } return result; case 1: // looking for table names in the given schema MockSchema schema = schemas.get(names.get(0)); if (schema == null) { return Collections.emptyList(); } result = new ArrayList<SqlMoniker>(); for (String tableName : schema.tableNames) { result.add(new SqlMonikerImpl(tableName, SqlMonikerType.Table)); } return result; default: return Collections.emptyList(); } }
protected RexNode register(RexNode expr) { final String key = expr.toString(); final RexNode previous = mapDigestToExpr.put(key, expr); if (!allowDups && (previous != null)) { throw new SubExprExistsException(expr); } return expr; }
/** * Adds on to the existing join condition reference counts the references from the new join * condition. * * @param multiJoinInputs inputs into the new MultiJoinRel * @param nTotalFields total number of fields in the MultiJoinRel * @param joinCondition the new join condition * @param origJoinFieldRefCounts existing join condition reference counts * @param newJoinFieldRefCountsMap map containing the new join condition reference counts, indexed * by input # */ private void addOnJoinFieldRefCounts( RelNode[] multiJoinInputs, int nTotalFields, RexNode joinCondition, List<int[]> origJoinFieldRefCounts, Map<Integer, int[]> newJoinFieldRefCountsMap) { // count the input references in the join condition int[] joinCondRefCounts = new int[nTotalFields]; joinCondition.accept(new InputReferenceCounter(joinCondRefCounts)); // first, make a copy of the ref counters int nInputs = multiJoinInputs.length; int currInput = 0; for (int[] origRefCounts : origJoinFieldRefCounts) { newJoinFieldRefCountsMap.put(currInput, (int[]) origRefCounts.clone()); currInput++; } // add on to the counts for each input into the MultiJoinRel the // reference counts computed for the current join condition currInput = -1; int startField = 0; int nFields = 0; for (int i = 0; i < nTotalFields; i++) { if (joinCondRefCounts[i] == 0) { continue; } while (i >= (startField + nFields)) { startField += nFields; currInput++; assert (currInput < nInputs); nFields = multiJoinInputs[currInput].getRowType().getFieldCount(); } int[] refCounts = newJoinFieldRefCountsMap.get(currInput); refCounts[i - startField] += joinCondRefCounts[i]; } }
private List<AggregateCall> transformAggCalls( RelDataTypeFactory typeFactory, int nGroupCols, List<AggregateCall> origCalls) { List<AggregateCall> newCalls = new ArrayList<AggregateCall>(); int iInput = nGroupCols; for (AggregateCall origCall : origCalls) { if (origCall.isDistinct() || !SUPPORTED_AGGREGATES.containsKey(origCall.getAggregation().getClass())) { return null; } Aggregation aggFun; RelDataType aggType; if (origCall.getAggregation().getName().equals("COUNT")) { aggFun = new SqlSumEmptyIsZeroAggFunction(origCall.getType()); SqlAggFunction af = (SqlAggFunction) aggFun; final AggregateRelBase.AggCallBinding binding = new AggregateRelBase.AggCallBinding( typeFactory, af, Collections.singletonList(origCall.getType()), nGroupCols); // count(any) is always not null, however nullability of sum might // depend on the number of columns in GROUP BY. // Here we use SUM0 since we are sure we will not face nullable // inputs nor we'll face empty set. aggType = af.inferReturnType(binding); } else { aggFun = origCall.getAggregation(); aggType = origCall.getType(); } AggregateCall newCall = new AggregateCall( aggFun, origCall.isDistinct(), Collections.singletonList(iInput), aggType, origCall.getName()); newCalls.add(newCall); ++iInput; } return newCalls; }
static { SUPPORTED_AGGREGATES.put(SqlMinMaxAggFunction.class, true); SUPPORTED_AGGREGATES.put(SqlCountAggFunction.class, true); SUPPORTED_AGGREGATES.put(SqlSumAggFunction.class, true); SUPPORTED_AGGREGATES.put(SqlSumEmptyIsZeroAggFunction.class, true); }
protected RexNode lookup(RexNode expr) { return mapDigestToExpr.get(expr.toString()); }
protected void registerSchema(MockSchema schema) { schemas.put(schema.name, schema); }