[BugFix](table-value-function) Fix backends() tvf (#19452)

Change the `Alive/SystemDecommissioned/ClusterDecommissioned` field type of the `backends()`tvf to bool
This commit is contained in:
Tiewei Fang
2023-05-11 07:49:27 +08:00
committed by GitHub
parent 2d1f597413
commit 95833426e8
5 changed files with 50 additions and 31 deletions

View File

@ -143,6 +143,12 @@ Status VMetaScanner::_fill_block_with_remote_data(const std::vector<MutableColum
col_ptr = &nullable_column->get_nested_column();
}
switch (slot_desc->type().type) {
case TYPE_BOOLEAN: {
bool data = _batch_data[_row_idx].column_value[col_idx].boolVal;
reinterpret_cast<vectorized::ColumnVector<vectorized::UInt8>*>(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<vectorized::ColumnVector<vectorized::Int32>*>(col_ptr)

View File

@ -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)));

View File

@ -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<String> columnNames, TMetadataType type) {
List<String> columnNames, TMetadataType type) throws TException {
List<TRow> fullColumnsRow = result.getDataBatch();
List<TRow> 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);
}

View File

@ -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();

View File

@ -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)
}