reuvenlax commented on code in PR #41746:
URL: https://github.com/apache/beam/pull/41746#discussion_r4732748376
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java:
##########
@@ -43,54 +36,61 @@
*/
@SuppressWarnings("rawtypes")
public class RowWithGetters<T extends @NonNull Object> extends Row {
+ private static final Object NULL_SENTINEL = new Object();
+
private final T getterTarget;
private final TypeDescriptor<?> getterTargetType;
private final List<FieldValueGetter<T, Object>> getters;
- private @Nullable Map<Integer, @Nullable Object> cache = null;
+ // Null slot means uncached; NULL_SENTINEL means cached null.
AtomicReferenceArray ensures
+ // safe JMM publication of cached collections across concurrent readers.
+ private transient volatile @Nullable AtomicReferenceArray<@Nullable Object>
cache = null;
RowWithGetters(
Schema schema,
Factory<List<FieldValueGetter<T, Object>>> getterFactory,
T getterTarget,
TypeDescriptor<?> getterTargetType) {
+ this(schema, getterFactory.create(getterTargetType, schema), getterTarget,
getterTargetType);
+ }
+
+ RowWithGetters(
+ Schema schema,
+ List<FieldValueGetter<T, Object>> getters,
+ T getterTarget,
+ TypeDescriptor<?> getterTargetType) {
super(schema);
this.getterTarget = getterTarget;
this.getterTargetType = getterTargetType;
- this.getters = getterFactory.create(getterTargetType, schema);
+ this.getters = getters;
}
@Override
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})
public <W> W getValue(int fieldIdx) {
- Field field = getSchema().getField(fieldIdx);
- boolean cacheField = cacheFieldType(field);
-
- if (cacheField && cache == null) {
- cache = new TreeMap<>();
- }
-
+ Schema schema = getSchema();
@Nullable Object fieldValue;
- if (cacheField) {
- if (cache == null) {
- cache = new TreeMap<>();
+ int cacheSlot = schema.getContainerCacheSlot(fieldIdx);
+ if (cacheSlot >= 0) {
+ AtomicReferenceArray<@Nullable Object> localCache = cache;
+ if (localCache == null) {
Review Comment:
not worth it: rows are rarely accessed from multiple threads, and eager
evaluation could hurt performance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]