@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { fd.setImmutableStates(context.getType(expr)); } };
@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); } }
@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)); }
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; }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue()); IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue()); fd.setImmutableStates(type0, type1); } }
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; }
private IAType computeContentType(IVariableTypeEnvironment env, AbstractFunctionCallExpression f) throws AlgebricksException { IAType currentType = null; for (int k = 0; k < f.getArguments().size(); k++) { IAType type = (IAType) env.getType(f.getArguments().get(k).getValue()); if (type.getTypeTag() == ATypeTag.UNION || (currentType != null && !currentType.equals(type))) { return null; } currentType = type; } return currentType; }
private boolean rewriteSwitchCase(ILogicalOperator op, AbstractFunctionCallExpression func, IOptimizationContext context) throws AlgebricksException { IVariableTypeEnvironment env = op.computeInputTypeEnvironment(context); IAType producedType = (IAType) env.getType(func); List<Mutable<ILogicalExpression>> argRefs = func.getArguments(); int argSize = argRefs.size(); boolean rewritten = false; for (int argIndex = 2; argIndex < argSize; argIndex += (argIndex + 2 == argSize) ? 1 : 2) { Mutable<ILogicalExpression> argRef = argRefs.get(argIndex); if (rewriteFunctionArgument(argRef, producedType, env)) { rewritten = true; } } return rewritten; }
private boolean rewriteFunction(ILogicalOperator op, AbstractFunctionCallExpression func, IntPredicate argChecker, IOptimizationContext context) throws AlgebricksException { IVariableTypeEnvironment env = op.computeInputTypeEnvironment(context); IAType producedType = (IAType) env.getType(func); List<Mutable<ILogicalExpression>> argRefs = func.getArguments(); int argSize = argRefs.size(); boolean rewritten = false; for (int argIndex = 0; argIndex < argSize; argIndex++) { if (argChecker == null || argChecker.test(argIndex)) { rewritten |= rewriteFunctionArgument(argRefs.get(argIndex), producedType, env); } } return rewritten; }
@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 void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); fd.setImmutableStates(TypeComputeUtils.getActualType(t)); } };
@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()); ILogicalExpression le = f.getArguments().get(1).getValue(); IAType type1 = (IAType) context.getType(le); if (type0.getTypeTag().equals(ATypeTag.ANY)) { type0 = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE; } if (type1.getTypeTag().equals(ATypeTag.ANY)) { type1 = DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE; } fd.setImmutableStates(outType, type0, type1); } }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; IAType rt = TypeCastUtils.getRequiredType(funcExpr); IAType it = (IAType) context.getType(funcExpr.getArguments().get(0).getValue()); fd.setImmutableStates(rt, it); } }
@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()); ILogicalExpression listExpr = f.getArguments().get(1).getValue(); IAType type1 = (IAType) context.getType(listExpr); if (type0.getTypeTag().equals(ATypeTag.ANY)) { type0 = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE; } if (type1.getTypeTag().equals(ATypeTag.ANY)) { type1 = DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE; } fd.setImmutableStates(outType, type0, type1); } }
@Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression; IAType type = (IAType) env.getType(f.getArguments().get(0).getValue()); if (type.getTypeTag() != ATypeTag.UNION) { // directly return the input type if it is not a union return type; } AUnionType unionType = (AUnionType) type; return unionType.getActualType(); } }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; List<Mutable<ILogicalExpression>> args = f.getArguments(); int n = args.size(); ARecordType[] argRecordTypes = new ARecordType[n]; for (int i = 0; i < n; i++) { IAType argType = (IAType) context.getType(args.get(i).getValue()); IAType t = TypeComputeUtils.getActualType(argType); if (t.getTypeTag() == ATypeTag.OBJECT) { argRecordTypes[i] = (ARecordType) t; } } fd.setImmutableStates((Object[]) argRecordTypes); } }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType[] argsTypes = new IAType[fce.getArguments().size()]; int i = 0; for (Mutable<ILogicalExpression> arg : fce.getArguments()) { argsTypes[i] = TypeComputeUtils.getActualType((IAType) context.getType(arg.getValue())); i++; } fd.setImmutableStates((Object[]) argsTypes); } };
private boolean rewriteExpressions(List<Mutable<ILogicalExpression>> expressions, IVariableTypeEnvironment env) throws AlgebricksException { boolean changed = false; for (Mutable<ILogicalExpression> exprRef : expressions) { ILogicalExpression expr = exprRef.getValue(); if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression argFuncExpr = (AbstractFunctionCallExpression) expr; IAType exprType = (IAType) env.getType(argFuncExpr); if (StaticTypeCastUtil.rewriteListExpr(argFuncExpr, exprType, exprType, env)) { TypeCastUtils.resetRequiredAndInputTypes(argFuncExpr); changed = true; } } } return changed; }
private boolean rewriteFunctionArgument(Mutable<ILogicalExpression> argRef, IAType funcOutputType, IVariableTypeEnvironment env) throws AlgebricksException { ILogicalExpression argExpr = argRef.getValue(); IAType type = (IAType) env.getType(argExpr); if (TypeResolverUtil.needsCast(funcOutputType, type)) { // Injects a cast call to cast the data type to the produced type of the function call. ScalarFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE), new ArrayList<>(Collections.singletonList(new MutableObject<>(argExpr)))); castFunc.setSourceLocation(argExpr.getSourceLocation()); TypeCastUtils.setRequiredAndInputTypes(castFunc, funcOutputType, type); argRef.setValue(castFunc); return true; } return false; } }
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); ATypeTag typeTag = t.getTypeTag(); if (typeTag.equals(ATypeTag.OBJECT)) { fd.setImmutableStates(t); } else if (typeTag.equals(ATypeTag.ANY)) { fd.setImmutableStates(RecordUtil.FULLY_OPEN_RECORD_TYPE); } else { throw new NotImplementedException("parse-geojson for data of type " + t); } } }