diff --git a/be/src/vec/exec/scan/vmeta_scanner.cpp b/be/src/vec/exec/scan/vmeta_scanner.cpp index 50e81ebe09..4a59804e6a 100644 --- a/be/src/vec/exec/scan/vmeta_scanner.cpp +++ b/be/src/vec/exec/scan/vmeta_scanner.cpp @@ -143,6 +143,12 @@ Status VMetaScanner::_fill_block_with_remote_data(const std::vectorget_nested_column(); } switch (slot_desc->type().type) { + case TYPE_BOOLEAN: { + bool data = _batch_data[_row_idx].column_value[col_idx].boolVal; + reinterpret_cast*>(col_ptr) + ->insert_value((uint8_t)data); + break; + } case TYPE_INT: { int64_t data = _batch_data[_row_idx].column_value[col_idx].intVal; reinterpret_cast*>(col_ptr) diff --git a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/BackendsTableValuedFunction.java b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/BackendsTableValuedFunction.java index fbf349c517..507f0ee93b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/BackendsTableValuedFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/BackendsTableValuedFunction.java @@ -110,9 +110,9 @@ public class BackendsTableValuedFunction extends MetadataTableValuedFunction { resColumns.add(new Column("BrpcPort", ScalarType.createType(PrimitiveType.INT))); resColumns.add(new Column("LastStartTime", ScalarType.createStringType())); resColumns.add(new Column("LastHeartbeat", ScalarType.createStringType())); - resColumns.add(new Column("Alive", ScalarType.createStringType())); - resColumns.add(new Column("SystemDecommissioned", ScalarType.createStringType())); - resColumns.add(new Column("ClusterDecommissioned", ScalarType.createStringType())); + resColumns.add(new Column("Alive", ScalarType.createType(PrimitiveType.BOOLEAN))); + resColumns.add(new Column("SystemDecommissioned", ScalarType.createType(PrimitiveType.BOOLEAN))); + resColumns.add(new Column("ClusterDecommissioned", ScalarType.createType(PrimitiveType.BOOLEAN))); resColumns.add(new Column("TabletNum", ScalarType.createType(PrimitiveType.BIGINT))); resColumns.add(new Column("DataUsedCapacity", ScalarType.createType(PrimitiveType.BIGINT))); resColumns.add(new Column("AvailCapacity", ScalarType.createType(PrimitiveType.BIGINT))); diff --git a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java index 9b75101cc6..93b70203ea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java @@ -19,6 +19,7 @@ package org.apache.doris.tablefunction; import org.apache.doris.alter.DecommissionType; import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; import org.apache.doris.common.MetaNotFoundException; import org.apache.doris.common.util.TimeUtils; import org.apache.doris.datasource.HMSExternalCatalog; @@ -47,6 +48,7 @@ import org.apache.iceberg.Snapshot; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.thrift.TException; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -59,7 +61,7 @@ import java.util.concurrent.TimeUnit; public class MetadataGenerator { private static final Logger LOG = LogManager.getLogger(MetadataGenerator.class); - public static TFetchSchemaTableDataResult getMetadataTable(TFetchSchemaTableDataRequest request) { + public static TFetchSchemaTableDataResult getMetadataTable(TFetchSchemaTableDataRequest request) throws TException { if (!request.isSetMetadaTableParams()) { return errorResult("Metadata table params is not set. "); } @@ -179,17 +181,18 @@ public class MetadataGenerator { } trow.addToColumnValue(new TCell().setStringVal(TimeUtils.longToTimeString(backend.getLastStartTime()))); trow.addToColumnValue(new TCell().setStringVal(TimeUtils.longToTimeString(backend.getLastUpdateMs()))); - trow.addToColumnValue(new TCell().setStringVal(String.valueOf(backend.isAlive()))); + trow.addToColumnValue(new TCell().setBoolVal(backend.isAlive())); + if (backend.isDecommissioned() && backend.getDecommissionType() == DecommissionType.ClusterDecommission) { - trow.addToColumnValue(new TCell().setStringVal("false")); - trow.addToColumnValue(new TCell().setStringVal("true")); + trow.addToColumnValue(new TCell().setBoolVal(false)); + trow.addToColumnValue(new TCell().setBoolVal(true)); } else if (backend.isDecommissioned() && backend.getDecommissionType() == DecommissionType.SystemDecommission) { - trow.addToColumnValue(new TCell().setStringVal("true")); - trow.addToColumnValue(new TCell().setStringVal("false")); + trow.addToColumnValue(new TCell().setBoolVal(true)); + trow.addToColumnValue(new TCell().setBoolVal(false)); } else { - trow.addToColumnValue(new TCell().setStringVal("false")); - trow.addToColumnValue(new TCell().setStringVal("false")); + trow.addToColumnValue(new TCell().setBoolVal(false)); + trow.addToColumnValue(new TCell().setBoolVal(false)); } trow.addToColumnValue(new TCell().setLongVal(tabletNum)); @@ -266,27 +269,18 @@ public class MetadataGenerator { } private static void filterColumns(TFetchSchemaTableDataResult result, - List columnNames, TMetadataType type) { + List columnNames, TMetadataType type) throws TException { List fullColumnsRow = result.getDataBatch(); List filterColumnsRows = Lists.newArrayList(); for (TRow row : fullColumnsRow) { TRow filterRow = new TRow(); - for (String columnName : columnNames) { - Integer index = 0; - switch (type) { - case ICEBERG: - index = IcebergTableValuedFunction.getColumnIndexFromColumnName(columnName); - break; - case BACKENDS: - index = BackendsTableValuedFunction.getColumnIndexFromColumnName(columnName); - break; - case RESOURCE_GROUPS: - index = ResourceGroupsTableValuedFunction.getColumnIndexFromColumnName(columnName); - break; - default: - break; + try { + for (String columnName : columnNames) { + Integer index = MetadataTableValuedFunction.getColumnIndexFromColumnName(type, columnName); + filterRow.addToColumnValue(row.getColumnValue().get(index)); } - filterRow.addToColumnValue(row.getColumnValue().get(index)); + } catch (AnalysisException e) { + throw new TException(e); } filterColumnsRows.add(filterRow); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataTableValuedFunction.java b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataTableValuedFunction.java index 0b30ea18c7..45e521a9e5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataTableValuedFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataTableValuedFunction.java @@ -18,6 +18,7 @@ package org.apache.doris.tablefunction; import org.apache.doris.analysis.TupleDescriptor; +import org.apache.doris.common.AnalysisException; import org.apache.doris.planner.PlanNodeId; import org.apache.doris.planner.ScanNode; import org.apache.doris.planner.external.MetadataScanNode; @@ -25,6 +26,20 @@ import org.apache.doris.thrift.TMetaScanRange; import org.apache.doris.thrift.TMetadataType; public abstract class MetadataTableValuedFunction extends TableValuedFunctionIf { + public static Integer getColumnIndexFromColumnName(TMetadataType type, String columnName) + throws AnalysisException { + switch (type) { + case BACKENDS: + return BackendsTableValuedFunction.getColumnIndexFromColumnName(columnName); + case ICEBERG: + return IcebergTableValuedFunction.getColumnIndexFromColumnName(columnName); + case RESOURCE_GROUPS: + return ResourceGroupsTableValuedFunction.getColumnIndexFromColumnName(columnName); + default: + throw new AnalysisException("Unknown Metadata TableValuedFunction type"); + } + } + public abstract TMetadataType getMetadataType(); public abstract TMetaScanRange getMetaScanRange(); diff --git a/regression-test/suites/correctness_p0/table_valued_function/test_backends_tvf.groovy b/regression-test/suites/correctness_p0/table_valued_function/test_backends_tvf.groovy index 3f95bcc04b..a13ee3fec5 100644 --- a/regression-test/suites/correctness_p0/table_valued_function/test_backends_tvf.groovy +++ b/regression-test/suites/correctness_p0/table_valued_function/test_backends_tvf.groovy @@ -25,25 +25,29 @@ suite("test_backends_tvf") { table = sql """ select BackendId, HostName, Alive, TotalCapacity, Version, NodeRole from backends();""" assertTrue(table.size() > 0) // row should > 0 assertTrue(table[0].size == 6) // column should be 26 - assertEquals("true", table[0][2]) + assertEquals(true, table[0][2]) // case insensitive table = sql """ select backendid, Hostname, alive, Totalcapacity, version, nodeRole from backends();""" assertTrue(table.size() > 0) // row should > 0 assertTrue(table[0].size == 6) // column should be 26 - assertEquals("true", table[0][2]) + assertEquals(true, table[0][2]) // test aliase columns table = sql """ select backendid as id, Hostname as name, alive, NodeRole as r from backends();""" assertTrue(table.size() > 0) // row should > 0 assertTrue(table[0].size == 4) // column should be 26 - assertEquals("true", table[0][2]) + assertEquals(true, table[0][2]) // test changing position of columns table = sql """ select Hostname as name, NodeRole as r, alive, ip from backends();""" assertTrue(table.size() > 0) // row should > 0 assertTrue(table[0].size == 4) // column should be 26 - assertEquals("true", table[0][2]) + assertEquals(true, table[0][2]) + def res = sql """ select count(*) from backends() where alive = 1; """ + assertTrue(res[0][0] > 0) + res = sql """ select count(*) from backends() where alive = true; """ + assertTrue(res[0][0] > 0) } \ No newline at end of file