@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { fd.setImmutableStates(context.getType(expr)); } };
private void checkTypeConsistency(IVariableTypeEnvironment expected, List<LogicalVariable> expectedVariables, IVariableTypeEnvironment actual, List<LogicalVariable> actualVariables) throws AlgebricksException { for (int i = 0; i < expectedVariables.size(); i++) { Object expectedType = expected.getVarType(expectedVariables.get(i)); Object actualType = actual.getVarType(actualVariables.get(i)); if (!expectedType.equals(actualType)) { if (AlgebricksConfig.ALGEBRICKS_LOGGER.isWarnEnabled()) { AlgebricksConfig.ALGEBRICKS_LOGGER .warn("Type of two variables are not equal." + expectedVariables.get(i) + " is of type: " + expectedType + actualVariables.get(i) + " is of type: " + actualType); } } } }
ILogicalExpression expr = p.second.getValue(); if (p.first != null) { env.setVarType(p.first, env2.getType(expr)); if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { LogicalVariable v1 = ((VariableReferenceExpression) expr).getVariableReference(); env.setVarType(v1, env2.getVarType(v1)); env.setVarType(v2, env2.getVarType(v2)); ILogicalExpression expr = p.second.getValue(); if (p.first != null) { env.setVarType(p.first, env2.getType(expr)); } else { VariableReferenceExpression vre = (VariableReferenceExpression) p.second.getValue(); LogicalVariable v2 = vre.getVariableReference(); env.setVarType(v2, env2.getVarType(v2));
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx); Object t = env.getType(expression.getValue()); env.setVarType(variables.get(0), t); if (positionalVariable != null) { env.setVarType(positionalVariable, positionalVariableType); } return env; }
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment typeEnv = ctx.getOutputTypeEnvironment(inputs.get(0).getValue()); for (int i = 1; i < inputs.size(); i++) { checkTypeConsistency(typeEnv, compareVars.get(0), ctx.getOutputTypeEnvironment(inputs.get(i).getValue()), compareVars.get(i)); } IVariableTypeEnvironment env = new NonPropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMetadataProvider()); int i = 0; for (; i < compareVars.get(0).size(); i++) { env.setVarType(outputVars.get(i), typeEnv.getVarType(compareVars.get(0).get(i))); } if (extraVars != null) { for (int k = 0; k < extraVars.get(0).size(); k++) { env.setVarType(outputVars.get(i + k), typeEnv.getVarType(extraVars.get(0).get(k))); } } return typeEnv; }
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx); // If the secondary index is not length-partitioned, create one new // output variable - token. // If the secondary index is length-partitioned, create two new output // variables - token, number of token. // The type of this variable will be the same as the type of the // secondary key. If the secondary is list type, then the element type // of the list. // Along with PK, the tokenizer will generate [token, number of tokens, // PK] pairs. for (int i = 0; i < tokenizeVars.size(); i++) { env.setVarType(tokenizeVars.get(i), tokenizeVarTypes.get(i)); } return env; }
private void substVarTypes(ILogicalOperator op, Pair<LogicalVariable, LogicalVariable> arg) throws AlgebricksException { if (ctx == null) { return; } IVariableTypeEnvironment env = ctx.getOutputTypeEnvironment(op); if (env != null) { env.substituteProducedVariable(arg.first, arg.second); } }
aggOpInputEnv.setVarType(var, outputEnv.getVarType(var)); i = 0; for (LogicalVariable v : gbyCols) { Object type = aggOpInputEnv.getVarType(v); if (orderColumns[i].getOrder() == OrderKind.ASC) { compFactories[i] = bcfProvider.getBinaryComparatorFactory(type, true); aggOpInputEnv.setVarType(usedVars.get(i++), type); normalizedKeyFactory = null; Object type = aggOpInputEnv.getVarType(gbyCols.get(0)); normalizedKeyFactory = orderColumns[0].getOrder() == OrderKind.ASC ? nkcfProvider.getNormalizedKeyComputerFactory(type, true)
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx); Object[] types = dataSource.getSchemaTypes(); int i = 0; for (LogicalVariable v : variables) { env.setVarType(v, types[i]); ++i; } return env; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; IAType outType = (IAType) context.getType(expr); IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue()); IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue()); fd.setImmutableStates(outType, type0, type1); } }
private Object getType(IVariableTypeEnvironment env, LogicalVariable var) throws AlgebricksException { Object type = env.getVarType(var); if (type == null) { throw new AlgebricksException("Failed typing union operator: no type for variable " + var); } return type; } }
aggOpInputEnv.setVarType(var, outputEnv.getVarType(var)); aggOpInputEnv.setVarType(usedVars.get(i++), type);
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env; if (propagateInput) { env = createPropagatingAllInputsTypeEnvironment(ctx); } else { env = new NonPropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMetadataProvider()); } int n = variables.size(); for (int i = 0; i < n; i++) { env.setVarType(variables.get(i), variableTypes.get(i)); } return env; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { ARecordType rt = (ARecordType) context.getType(expr); fd.setImmutableStates(rt, computeOpenFields((AbstractFunctionCallExpression) expr, rt)); }
public static IBinaryHashFunctionFamily[] variablesToBinaryHashFunctionFamilies( Collection<LogicalVariable> varLogical, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException { IBinaryHashFunctionFamily[] funFamilies = new IBinaryHashFunctionFamily[varLogical.size()]; int i = 0; IBinaryHashFunctionFamilyProvider bhffProvider = context.getBinaryHashFunctionFamilyProvider(); for (LogicalVariable var : varLogical) { Object type = env.getVarType(var); funFamilies[i++] = bhffProvider.getBinaryHashFunctionFamily(type); } return funFamilies; }
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx); int n = variables.size(); for (int i = 0; i < n; i++) { env.setVarType(variables.get(i), ctx.getExpressionTypeComputer().getType(expressions.get(i).getValue(), ctx.getMetadataProvider(), env)); } return env; }
private boolean exprIsRecord(IVariableTypeEnvironment typeEnvironment, ILogicalExpression recordExpr) throws AlgebricksException { if (recordExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { IAType type = (IAType) typeEnvironment.getType(recordExpr); return type != null && type.getTypeTag() == ATypeTag.OBJECT; } return false; }
public static IBinaryComparatorFactory[] variablesToAscBinaryComparatorFactories(List<LogicalVariable> varLogical, int start, int size, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException { IBinaryComparatorFactory[] compFactories = new IBinaryComparatorFactory[size]; IBinaryComparatorFactoryProvider bcfProvider = context.getBinaryComparatorFactoryProvider(); for (int i = 0; i < size; i++) { Object type = env.getVarType(varLogical.get(start + i)); compFactories[i] = bcfProvider.getBinaryComparatorFactory(type, true); } return compFactories; }
@Override public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException { IVariableTypeEnvironment env = createNestedPlansPropagatingTypeEnvironment(ctx, true); for (int i = 0, n = variables.size(); i < n; i++) { env.setVarType(variables.get(i), ctx.getExpressionTypeComputer().getType(expressions.get(i).getValue(), ctx.getMetadataProvider(), env)); } return env; }
private static ILogicalExpression findFieldByIndexFromRecordConstructor(Object index, AbstractFunctionCallExpression fce, IVariableTypeEnvironment typeEnvironment) throws AlgebricksException { Integer fieldIndex = (Integer) index; ARecordType recordType = (ARecordType) typeEnvironment.getType(fce); String[] closedFieldNames = recordType.getFieldNames(); return closedFieldNames.length > fieldIndex ? findFieldByNameFromRecordConstructor(closedFieldNames[fieldIndex], fce) : null; }