Skip to content

Commit e8ddcff

Browse files
authored
Using typedGet with type default in FieldEvaluator (#108)
1 parent c80e60a commit e8ddcff

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5151
<maven.compiler.source>1.8</maven.compiler.source>
5252
<maven.compiler.target>1.8</maven.compiler.target>
53-
<bullet.record.version>1.2.0</bullet.record.version>
53+
<bullet.record.version>1.2.1</bullet.record.version>
5454
<sketches.version>0.9.1</sketches.version>
5555
</properties>
5656

src/main/java/com/yahoo/bullet/querying/evaluators/FieldEvaluator.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.yahoo.bullet.typesystem.TypedObject;
1313

1414
import java.io.Serializable;
15+
import java.util.Set;
1516

1617
/**
1718
* An evaluator that extracts a given field from a {@link BulletRecord}. This is the only evaluator that directly takes a
@@ -45,36 +46,37 @@ private static FieldExtractor getFieldExtractor(FieldExpression fieldExpression)
4546
final String field = fieldExpression.getField();
4647
final Serializable key = fieldExpression.getKey();
4748
final Serializable subKey = fieldExpression.getSubKey();
49+
final Type fieldType = fieldExpression.getType() != null ? fieldExpression.getType() : Type.UNKNOWN;
4850

4951
if (key instanceof String) {
5052
if (subKey instanceof String) {
51-
return record -> record.typedGet(field, (String) key, (String) subKey);
53+
return record -> record.typedGet(field, (String) key, (String) subKey, getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
5254
} else if (subKey instanceof Expression) {
5355
final Evaluator subKeyEvaluator = ((Expression) subKey).getEvaluator();
5456
return record -> {
5557
TypedObject subKeyArg = subKeyEvaluator.evaluate(record);
5658
if (subKeyArg.isNull()) {
5759
return TypedObject.NULL;
5860
}
59-
return record.typedGet(field, (String) key, (String) subKeyArg.getValue());
61+
return record.typedGet(field, (String) key, (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
6062
};
6163
} else {
62-
return record -> record.typedGet(field, (String) key);
64+
return record -> record.typedGet(field, (String) key, getSuperType(Type.MAPS, fieldType));
6365
}
6466
} else if (key instanceof Integer) {
6567
if (subKey instanceof String) {
66-
return record -> record.typedGet(field, (Integer) key, (String) subKey);
68+
return record -> record.typedGet(field, (Integer) key, (String) subKey, getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
6769
} else if (subKey instanceof Expression) {
6870
final Evaluator subKeyEvaluator = ((Expression) subKey).getEvaluator();
6971
return record -> {
7072
TypedObject subKeyArg = subKeyEvaluator.evaluate(record);
7173
if (subKeyArg.isNull()) {
7274
return TypedObject.NULL;
7375
}
74-
return record.typedGet(field, (Integer) key, (String) subKeyArg.getValue());
76+
return record.typedGet(field, (Integer) key, (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
7577
};
7678
} else {
77-
return record -> record.typedGet(field, (Integer) key);
79+
return record -> record.typedGet(field, (Integer) key, getSuperType(Type.LISTS, fieldType));
7880
}
7981
} else if (key instanceof Expression) {
8082
final Evaluator keyEvaluator = ((Expression) key).getEvaluator();
@@ -86,9 +88,9 @@ private static FieldExtractor getFieldExtractor(FieldExpression fieldExpression)
8688
}
8789
Type type = keyArg.getType();
8890
if (Type.isNumeric(type)) {
89-
return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKey);
91+
return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKey, getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
9092
} else {
91-
return record.typedGet(field, (String) keyArg.getValue(), (String) subKey);
93+
return record.typedGet(field, (String) keyArg.getValue(), (String) subKey, getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
9294
}
9395
};
9496
} else if (subKey instanceof Expression) {
@@ -104,9 +106,9 @@ private static FieldExtractor getFieldExtractor(FieldExpression fieldExpression)
104106
}
105107
Type type = keyArg.getType();
106108
if (Type.isNumeric(type)) {
107-
return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKeyArg.getValue());
109+
return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_LISTS, fieldType));
108110
} else {
109-
return record.typedGet(field, (String) keyArg.getValue(), (String) subKeyArg.getValue());
111+
return record.typedGet(field, (String) keyArg.getValue(), (String) subKeyArg.getValue(), getSuperSuperType(Type.COMPLEX_MAPS, fieldType));
110112
}
111113
};
112114
} else {
@@ -117,14 +119,22 @@ private static FieldExtractor getFieldExtractor(FieldExpression fieldExpression)
117119
}
118120
Type type = keyArg.getType();
119121
if (Type.isNumeric(type)) {
120-
return record.typedGet(field, ((Number) keyArg.getValue()).intValue());
122+
return record.typedGet(field, ((Number) keyArg.getValue()).intValue(), getSuperType(Type.LISTS, fieldType));
121123
} else {
122-
return record.typedGet(field, (String) keyArg.getValue());
124+
return record.typedGet(field, (String) keyArg.getValue(), getSuperType(Type.MAPS, fieldType));
123125
}
124126
};
125127
}
126128
} else {
127-
return record -> record.typedGet(field);
129+
return record -> record.typedGet(field, fieldType);
128130
}
129131
}
132+
133+
private static Type getSuperType(Set<Type> types, Type type) {
134+
return types.stream().filter(t -> t.getSubType() == type).findFirst().orElse(Type.UNKNOWN);
135+
}
136+
137+
private static Type getSuperSuperType(Set<Type> types, Type type) {
138+
return types.stream().filter(t -> t.getSubType().getSubType() == type).findFirst().orElse(Type.UNKNOWN);
139+
}
130140
}

src/main/java/com/yahoo/bullet/querying/tablefunctors/LateralViewBulletRecord.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.yahoo.bullet.querying.tablefunctors;
77

88
import com.yahoo.bullet.record.BulletRecord;
9+
import com.yahoo.bullet.typesystem.Type;
910
import com.yahoo.bullet.typesystem.TypedObject;
1011
import lombok.AccessLevel;
1112
import lombok.Getter;
@@ -89,11 +90,11 @@ public BulletRecord remove(String field) {
8990
}
9091

9192
@Override
92-
public TypedObject typedGet(String field) {
93+
public TypedObject typedGet(String field, Type hint) {
9394
if (culledFields.contains(field)) {
9495
return TypedObject.NULL;
9596
}
96-
return topRecord.hasField(field) ? topRecord.typedGet(field) : baseRecord.typedGet(field);
97+
return topRecord.hasField(field) ? topRecord.typedGet(field, hint) : baseRecord.typedGet(field, hint);
9798
}
9899

99100
@Override

0 commit comments

Comments
 (0)