korlov42 commented on code in PR #7333:
URL: https://github.com/apache/ignite-3/pull/7333#discussion_r2654905644


##########
modules/system-view/src/main/java/org/apache/ignite/internal/systemview/SystemViewManagerImpl.java:
##########
@@ -256,30 +267,223 @@ private static Map<String, ScannableView<?>> 
toScannableViews(String localNodeNa
     private static class ScannableView<T> {
         private final Publisher<InternalTuple> publisher;
 
-        private ScannableView(String localNodeName, SystemView<T> view) {
-            BinaryTupleSchema schema = tupleSchemaForView(view);
+        private ScannableView(ViewRowFactory rowFactory, SystemView<T> view) {
+            this.publisher = new TransformingPublisher<>(view.dataProvider(), 
object -> rowFactory.create(view, object));
+        }
 
-            this.publisher = new TransformingPublisher<>(view.dataProvider(), 
object -> {
-                BinaryTupleBuilder builder = new 
BinaryTupleBuilder(schema.elementCount());
+        Publisher<InternalTuple> scan() {
+            return publisher;
+        }
+    }
 
-                int offset = 0;
-                if (view instanceof NodeSystemView) {
-                    builder.appendString(localNodeName);
-                    offset++;
-                }
+    private abstract static class ViewRowFactory {
+        abstract <ViewSourceT> InternalTuple create(SystemView<ViewSourceT> 
view, ViewSourceT source);
+    }
 
-                for (int i = 0; i < view.columns().size(); i++) {
-                    SystemViewColumn<T, ?> column = view.columns().get(i);
+    private static class NodeViewRowFactory extends ViewRowFactory {
+        private final String nodeName;
 
-                    schema.appendValue(builder, i + offset, 
column.value().apply(object));
-                }
+        private NodeViewRowFactory(String nodeName) {
+            this.nodeName = nodeName;
+        }
 
-                return new BinaryTuple(schema.elementCount(), builder.build());
-            });
+        @Override
+        <ViewSourceT> InternalTuple create(SystemView<ViewSourceT> view, 
ViewSourceT source) {
+            return new NodeViewRow<>(nodeName, view, source);
         }
+    }
 
-        Publisher<InternalTuple> scan() {
-            return publisher;
+    private static class ClusterViewRowFactory extends ViewRowFactory {
+        private static final ViewRowFactory INSTANCE = new 
ClusterViewRowFactory();
+
+        @Override
+        <ViewSourceT> InternalTuple create(SystemView<ViewSourceT> view, 
ViewSourceT source) {
+            return new ClusterViewRow<>(view, source);
         }
     }
+
+    private static class NodeViewRow<T> extends AbstractViewRow {
+        private final String nodeName;
+        private final SystemView<T> view;
+        private final T source;
+
+        private NodeViewRow(String nodeName, SystemView<T> view, T source) {
+            this.nodeName = nodeName;
+            this.view = view;
+            this.source = source;
+        }
+
+        @Override
+        public int elementCount() {
+            return view.columns().size() + 1;
+        }
+
+        @Override
+        public ByteBuffer byteBuffer() {
+            throw new UnsupportedOperationException("byteBuffer");
+        }
+
+        @Override
+        <ReturnT> ReturnT value(int columnIndex) {
+            return columnIndex == 0 
+                    ? (ReturnT) nodeName
+                    : (ReturnT) view.columns().get(columnIndex - 
1).value().apply(source);
+        }
+    }
+
+    private static class ClusterViewRow<T> extends AbstractViewRow {
+        private final SystemView<T> view;
+        private final T source;
+
+        private ClusterViewRow(SystemView<T> view, T source) {
+            this.view = view;
+            this.source = source;
+        }
+
+        @Override
+        public int elementCount() {
+            return view.columns().size();
+        }
+
+        @Override
+        public ByteBuffer byteBuffer() {
+            throw new UnsupportedOperationException("byteBuffer");
+        }
+
+        @Override
+        <ReturnT> ReturnT value(int columnIndex) {
+            return (ReturnT) 
view.columns().get(columnIndex).value().apply(source);
+        }
+    }
+
+    private abstract static class AbstractViewRow implements InternalTuple {
+        abstract <T> T value(int columnIndex);
+
+        @Override
+        public boolean hasNullValue(int columnIndex) {
+            return value(columnIndex) == null;
+        }
+
+        @Override
+        public boolean booleanValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Boolean booleanValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public byte byteValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Byte byteValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public short shortValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Short shortValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public int intValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Integer intValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public long longValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Long longValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public float floatValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Float floatValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public double doubleValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Double doubleValueBoxed(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public BigDecimal decimalValue(int columnIndex, int scale) {
+            BigDecimal value = value(columnIndex);
+
+            return value.setScale(scale, RoundingMode.UNNECESSARY);
+        }
+
+        @Override
+        public String stringValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public byte[] bytesValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public UUID uuidValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public LocalDate dateValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public LocalTime timeValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public LocalDateTime dateTimeValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Instant timestampValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Period periodValue(int columnIndex) {
+            return value(columnIndex);
+        }
+
+        @Override
+        public Duration durationValue(int columnIndex) {
+            return value(columnIndex);
+        }

Review Comment:
   it's nice to have indeed, but not required. I believe the purpose is clear, 
so I ignore this comment



-- 
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]

Reply via email to