如何使用 azure-kusto-java 库按 java 中的列名获取单元格的值

How to get value of a cell by column name in java using azure-kusto-java library

public KustoResultSetTable executeKustoQuery(ClientImpl client, String query) {

    KustoResultSetTable mainTableResult = null;
    try {
        KustoOperationResult results = client.execute(databaseName, query);
        mainTableResult = results.getPrimaryResults();
    } catch (DataServiceException | DataClientException e) {

        errorHandler(e, "Error while retrieving results from kusto query!");
    }
    return mainTableResult;
}

上面的代码returns我是这种类型的结果

Name    | Age
XYZ AAA | 29

如何使用 Azure Kusto Java mainTableResult 对象

获取名称列下第一行的值

预期的字符串输出 - "XYZ AAA"

你可以这样做:

if (mainTableResult.first()) {
    int columnIndex = mainTableResult.findColumn("Name")
    return mainTableResult.getString(columnIndex);
} else {
    throw new UnsupportedOperationException(""); // Or any other error handling
}

完整版本为:

public String executeKustoQuery(ClientImpl client, String query) {

    KustoResultSetTable mainTableResult = null;
    try {
        KustoOperationResult results = client.execute("databaseName", query);
        mainTableResult = results.getPrimaryResults();
        if (mainTableResult.first()) {
            int columnIndex = mainTableResult.findColumn("Name")
            return mainTableResult.getString(columnIndex);
        } else {
            throw new UnsupportedOperationException(""); // Or any other error handling
        }
    } catch (DataServiceException | DataClientException e) {

        errorHandler(e, "Error while retrieving results from kusto query!");
    }
}