0
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;
}

上面的代码返回了这种类型的结果

Name    | Age
XYZ AAA | 29

如何使用 Azure Kusto JavamainTableResult对象获取名称列下第一行的值

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

4

1 回答 1

0

你可以做:

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!");
    }
}
于 2021-02-09T15:00:10.197 回答