@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression funCallExpr = (AbstractFunctionCallExpression) expr; Object[] samplingParameters = funCallExpr.getOpaqueParameters(); fd.setImmutableStates(samplingParameters[0]); } };
@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) { fd.setImmutableStates(compilerProps.getStringOffset()); } };
@Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps) throws AlgebricksException { AbstractFunctionCallExpression funCallExpr = (AbstractFunctionCallExpression) expr; Object[] sortingParameters = funCallExpr.getOpaqueParameters(); fd.setImmutableStates(sortingParameters[0], sortingParameters[1]); } };
@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)); }
@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)); } };
protected IFunctionDescriptor createCastFunction(boolean strictCast) throws AlgebricksException { IFunctionDescriptor castFuncDesc = metadataProvider.getFunctionManager() .lookupFunction(strictCast ? BuiltinFunctions.CAST_TYPE : BuiltinFunctions.CAST_TYPE_LAX); castFuncDesc.setSourceLocation(sourceLoc); castFuncDesc.setImmutableStates(enforcedItemType, itemType); return castFuncDesc; }
@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 fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); ATypeTag typeTag = t.getTypeTag(); switch (typeTag) { case OBJECT: { fd.setImmutableStates(t); break; } case ANY: { fd.setImmutableStates(RecordUtil.FULLY_OPEN_RECORD_TYPE); break; } default: { if (strict) { throw new NotImplementedException(fd.getIdentifier().getName() + " for data of type " + t); } else { fd.setImmutableStates(new Object[] { null }); } break; } } } }
@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); } } }
@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); } }
@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); } };
@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 { AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue()); AOrderedList fieldPath = (AOrderedList) (((AsterixConstantValue) ((ConstantExpression) fce.getArguments().get(1).getValue()) .getValue()).getObject()); List<String> listFieldPath = new ArrayList<>(); for (int i = 0; i < fieldPath.size(); i++) { listFieldPath.add(((AString) fieldPath.getItem(i)).getStringValue()); } switch (t.getTypeTag()) { case OBJECT: { fd.setImmutableStates(t, listFieldPath); break; } case ANY: fd.setImmutableStates(RecordUtil.FULLY_OPEN_RECORD_TYPE, listFieldPath); break; default: { throw new NotImplementedException("field-access-nested for data of type " + t); } } } }
@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()); switch (t.getTypeTag()) { case OBJECT: { fd.setImmutableStates(t); break; } case UNION: { AUnionType unionT = (AUnionType) t; if (unionT.isUnknownableType()) { IAType t2 = unionT.getActualType(); if (t2.getTypeTag() == ATypeTag.OBJECT) { fd.setImmutableStates(t2); break; } } throw new NotImplementedException("field-access-by-index for data of type " + t); } default: { throw new NotImplementedException("field-access-by-index for data of type " + 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 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 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); } }
@Test public void testCastLax() throws Exception { IFunctionDescriptor funcDesc = CastTypeLaxDescriptor.FACTORY.createFunctionDescriptor(); funcDesc.setImmutableStates(targetType, inType); ByteArrayOutputStream baos = new ByteArrayOutputStream(); AObjectSerializerDeserializer serDe = AObjectSerializerDeserializer.INSTANCE; serDe.serialize(inValue, new DataOutputStream(baos)); ConstantEvalFactory argEvalFactory = new ConstantEvalFactory(baos.toByteArray()); IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(new IScalarEvaluatorFactory[] { argEvalFactory }); IHyracksTaskContext ctx = mock(IHyracksTaskContext.class); IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx); VoidPointable resultPointable = new VoidPointable(); evaluator.evaluate(null, resultPointable); ByteArrayInputStream bais = new ByteArrayInputStream(resultPointable.getByteArray(), resultPointable.getStartOffset(), resultPointable.getLength()); IAObject resultValue = serDe.deserialize(new DataInputStream(bais)); Assert.assertTrue(String.format("Expected: %s, actual: %s", targetValue, resultValue), targetValue.deepEqual(resultValue)); }
IFunctionDescriptor fDesc = functionManager.lookupFunction(BuiltinFunctions.FIELD_ACCESS_BY_INDEX); fDesc.setSourceLocation(sourceLoc); fDesc.setImmutableStates(recType); return fDesc.createEvaluatorFactory( new IScalarEvaluatorFactory[] { recordEvalFactory, fldIndexEvalFactory }); IFunctionDescriptor fDesc = functionManager.lookupFunction(BuiltinFunctions.FIELD_ACCESS_NESTED); fDesc.setSourceLocation(sourceLoc); fDesc.setImmutableStates(recType, fldName); return fDesc.createEvaluatorFactory(new IScalarEvaluatorFactory[] { recordEvalFactory });