@Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { List<IAType> unionList = new ArrayList<>(); unionList.add(BuiltinType.ADATE); unionList.add(BuiltinType.ATIME); unionList.add(BuiltinType.ADATETIME); unionList.add(BuiltinType.AMISSING); unionList.add(BuiltinType.ANULL); return new AUnionType(unionList, "OptionalTemporalInstance"); }
public static IAType createNullableType(IAType type, String typeName) { if (type != null && type.getTypeTag() == ATypeTag.NULL) { return type; } List<IAType> unionList = new ArrayList<>(); if (type != null && type.getTypeTag() == ATypeTag.UNION) { AUnionType unionType = (AUnionType) type; unionList.addAll(unionType.getUnionList()); } else { unionList.add(type); } unionList.add(BuiltinType.ANULL); return new AUnionType(unionList, typeName); }
public static IAType createMissableType(IAType type, String typeName) { if (type != null && type.getTypeTag() == ATypeTag.MISSING) { return type; } List<IAType> unionList = new ArrayList<>(); if (type != null && type.getTypeTag() == ATypeTag.UNION) { AUnionType unionType = (AUnionType) type; unionList.addAll(unionType.getUnionList()); } else { unionList.add(type); } unionList.add(BuiltinType.AMISSING); return new AUnionType(unionList, typeName); }
unionTypes.add(convertFromJSON(fieldType)); return new AUnionType(unionTypes, "union");
@Test public void openRecordTypeTest() throws IOException, URISyntaxException { String[] ids = { "720549057849114629", "668950503552864257", "668945640186101761", "263602997047730177", "668948268605403136", "741701526859567104" }; // contruct type IAType geoFieldType = new ARecordType("GeoType", new String[] { "coordinates" }, new IAType[] { new AOrderedListType(AFLOAT, "point") }, true); List<IAType> unionTypeList = new ArrayList<>(); unionTypeList.add(geoFieldType); unionTypeList.add(ANULL); unionTypeList.add(AMISSING); IAType geoUnionType = new AUnionType(unionTypeList, "GeoType?"); ARecordType tweetRecordType = new ARecordType("TweetType", new String[] { "id", "geo" }, new IAType[] { AINT64, geoUnionType }, true); TweetParser parser = new TweetParser(tweetRecordType); CharArrayRecord record = new CharArrayRecord(); List<String> lines = Files.readAllLines(Paths.get(getClass().getResource("/test_tweets.txt").toURI())); ByteArrayOutputStream is = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(is); for (int iter1 = 0; iter1 < lines.size(); iter1++) { record.set(lines.get(iter1)); try { parser.parse(record, output); } catch (HyracksDataException e) { e.printStackTrace(); Assert.fail("Unexpected failure in parser."); } Assert.assertTrue((PA.getValue(parser, "aInt64")).toString().equals(ids[iter1])); } }