diff --git a/engine/api/src/main/java/io/deephaven/engine/table/Table.java b/engine/api/src/main/java/io/deephaven/engine/table/Table.java index 2fe32eab3b7..b4a101a397e 100644 --- a/engine/api/src/main/java/io/deephaven/engine/table/Table.java +++ b/engine/api/src/main/java/io/deephaven/engine/table/Table.java @@ -44,8 +44,7 @@ public interface Table extends TableDefinition getDefinition(); /** - * Provides column metadata in Table form. Convenience method, behaves exactly the same as - * getDefinition().getColumnDefinitionsTable(). + * Provides column metadata in Table form. * * @return A Table of metadata about this Table's columns. */ diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableDefaults.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableDefaults.java index 219a9a75ab7..9600e9021d0 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableDefaults.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableDefaults.java @@ -17,6 +17,7 @@ import io.deephaven.api.util.ConcurrentMethod; import io.deephaven.engine.util.ColumnFormatting; import io.deephaven.engine.liveness.LivenessScopeStack; +import io.deephaven.engine.util.TableTools; import io.deephaven.util.annotations.FinalDefault; import javax.annotation.Nullable; @@ -47,27 +48,7 @@ default Table coalesce() { @ConcurrentMethod @FinalDefault default Table meta() { - List columnNames = new ArrayList<>(); - List columnDataTypes = new ArrayList<>(); - List columnTypes = new ArrayList<>(); - List columnPartitioning = new ArrayList<>(); - for (ColumnDefinition cDef : getDefinition().getColumns()) { - columnNames.add(cDef.getName()); - final Class dataType = cDef.getDataType(); - final String dataTypeName = dataType.getCanonicalName(); - columnDataTypes.add(dataTypeName == null ? dataType.getName() : dataTypeName); - columnTypes.add(cDef.getColumnType().name()); - columnPartitioning.add(cDef.isPartitioning()); - } - final String[] resultColumnNames = {"Name", "DataType", "ColumnType", "IsPartitioning"}; - final Object[] resultValues = { - columnNames.toArray(String[]::new), - columnDataTypes.toArray(String[]::new), - columnTypes.toArray(String[]::new), - columnPartitioning.toArray(new Boolean[0]), - }; - - return new InMemoryTable(resultColumnNames, resultValues); + return TableTools.metaTable(getDefinition()); } @Override diff --git a/engine/table/src/main/java/io/deephaven/engine/util/TableTools.java b/engine/table/src/main/java/io/deephaven/engine/util/TableTools.java index aa3bcfcaf7e..62a873325e2 100644 --- a/engine/table/src/main/java/io/deephaven/engine/util/TableTools.java +++ b/engine/table/src/main/java/io/deephaven/engine/util/TableTools.java @@ -13,6 +13,7 @@ import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.RowSetFactory; import io.deephaven.engine.table.*; +import io.deephaven.engine.table.impl.InMemoryTable; import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder; import io.deephaven.internal.log.LoggerFactory; import io.deephaven.time.DateTimeUtils; @@ -768,6 +769,47 @@ public static Table newTable(TableDefinition definition, ColumnHolder... colu }; } + /** + * Creates a metadata {@link Table} representing the columns in {@code definition}. Will include the following + * columns: + *
+ *
Name
+ *
{@link ColumnDefinition#getName()}
+ *
DataType
+ *
From {@link ColumnDefinition#getDataType()}, result of {@link Class#getCanonicalName()} if non-{@code null}, + * else {@link Class#getName()}
+ *
ColumnType
+ *
{@code ColumnDefinition#getColumnType()}
+ *
IsPartitioning
+ *
{@link ColumnDefinition#isPartitioning()}
+ *
+ * + * @param definition the definition + * @return the metadata Table + */ + public static Table metaTable(TableDefinition definition) { + List columnNames = new ArrayList<>(); + List columnDataTypes = new ArrayList<>(); + List columnTypes = new ArrayList<>(); + List columnPartitioning = new ArrayList<>(); + for (ColumnDefinition cDef : definition.getColumns()) { + columnNames.add(cDef.getName()); + final Class dataType = cDef.getDataType(); + final String dataTypeName = dataType.getCanonicalName(); + columnDataTypes.add(dataTypeName == null ? dataType.getName() : dataTypeName); + columnTypes.add(cDef.getColumnType().name()); + columnPartitioning.add(cDef.isPartitioning()); + } + final String[] resultColumnNames = {"Name", "DataType", "ColumnType", "IsPartitioning"}; + final Object[] resultValues = { + columnNames.toArray(String[]::new), + columnDataTypes.toArray(String[]::new), + columnTypes.toArray(String[]::new), + columnPartitioning.toArray(new Boolean[0]), + }; + return new InMemoryTable(resultColumnNames, resultValues); + } + private static void checkSizes(ColumnHolder[] columnHolders) { final int[] sizes = Arrays.stream(columnHolders).mapToInt(ColumnHolder::size).toArray(); if (Arrays.stream(sizes).anyMatch(size -> size != sizes[0])) {