in data/src/main/java/com/microsoft/azure/kusto/data/KustoResultSetTable.java [84:183]
protected KustoResultSetTable(JsonNode jsonTable) {
if (jsonTable.has(TABLE_NAME_PROPERTY_NAME)) {
tableName = jsonTable.get(TABLE_NAME_PROPERTY_NAME).asText();
}
if (jsonTable.has(TABLE_ID_PROPERTY_NAME)) {
tableId = jsonTable.get(TABLE_ID_PROPERTY_NAME).asText();
}
tableId = jsonTable.has(TABLE_ID_PROPERTY_NAME) ? jsonTable.get(TABLE_ID_PROPERTY_NAME).asText() : EMPTY_STRING;
String tableKindString = jsonTable.has(TABLE_KIND_PROPERTY_NAME) ? jsonTable.get(TABLE_KIND_PROPERTY_NAME).asText() : EMPTY_STRING;
tableKind = StringUtils.isBlank(tableKindString) ? null : WellKnownDataSet.valueOf(tableKindString);
if (jsonTable.has(COLUMNS_PROPERTY_NAME) && jsonTable.get(COLUMNS_PROPERTY_NAME).getNodeType() == JsonNodeType.ARRAY) {
ArrayNode columnsJson = (ArrayNode) jsonTable.get(COLUMNS_PROPERTY_NAME);
if (columnsJson != null) {
columnsAsArray = new KustoResultColumn[columnsJson.size()];
for (int i = 0; i < columnsJson.size(); i++) {
JsonNode jsonCol = columnsJson.get(i);
// TODO yischoen Use CslFormat classes to validate columnType is valid, and that its value ("JsonNode obj" below) is valid for columnType
String columnType = jsonCol.has(COLUMN_TYPE_PROPERTY_NAME) ? jsonCol.get(COLUMN_TYPE_PROPERTY_NAME).asText() : EMPTY_STRING;
if (columnType.isEmpty()) {
columnType = jsonCol.has(COLUMN_TYPE_SECOND_PROPERTY_NAME) ? jsonCol.get(COLUMN_TYPE_SECOND_PROPERTY_NAME).asText() : EMPTY_STRING;
}
if (jsonCol.has(COLUMN_NAME_PROPERTY_NAME)) {
KustoResultColumn col = new KustoResultColumn(
jsonCol.has(COLUMN_NAME_PROPERTY_NAME) ? jsonCol.get(COLUMN_NAME_PROPERTY_NAME).asText() : EMPTY_STRING, columnType, i);
columnsAsArray[i] = col;
columns.put(jsonCol.has(COLUMN_NAME_PROPERTY_NAME) ? jsonCol.get(COLUMN_NAME_PROPERTY_NAME).asText() : EMPTY_STRING, col);
} else {
throw new JsonPropertyMissingException("Column Name property is missing in the json response");
}
}
}
}
ArrayNode exceptions;
ArrayNode jsonRows = null;
if (jsonTable.has(ROWS_PROPERTY_NAME) && jsonTable.get(ROWS_PROPERTY_NAME).getNodeType() == JsonNodeType.ARRAY) {
jsonRows = (ArrayNode) jsonTable.get(ROWS_PROPERTY_NAME);
}
if (jsonRows != null) {
List<List<Object>> values = new ArrayList<>();
for (int i = 0; i < jsonRows.size(); i++) {
JsonNode row = jsonRows.get(i);
if (jsonRows.get(i).getNodeType() == JsonNodeType.OBJECT) {
exceptions = row.has(EXCEPTIONS_PROPERTY_NAME) ? ((ArrayNode) row.get(EXCEPTIONS_PROPERTY_NAME)) : null;
if (exceptions != null) {
throw KustoServiceQueryError.fromOneApiErrorArray(exceptions, exceptions.size() == 1); // TODO: this is the same logic as before, should
// check with Yehezkel why isOneApi error is true
// if there is one exception
} else {
throw KustoServiceQueryError.fromOneApiErrorArray((ArrayNode) row.get(ONE_API_ERRORS_PROPERTY_NAME), true);
}
}
ArrayNode rowAsJsonArray = (ArrayNode) jsonRows.get(i);
List<Object> rowVector = new ArrayList<>();
for (int j = 0; j < rowAsJsonArray.size(); j++) {
JsonNode obj = rowAsJsonArray.get(j);
if (obj.isNull()) {
rowVector.add(null);
} else {
switch (rowAsJsonArray.get(j).getNodeType()) {
case STRING:
rowVector.add(obj.asText());
break;
case BOOLEAN:
rowVector.add(obj.asBoolean());
break;
case NUMBER:
if (obj.isInt()) {
rowVector.add(obj.asInt());
} else if (obj.isLong()) {
rowVector.add(obj.asLong());
} else if (obj.isBigDecimal()) {
rowVector.add(obj.decimalValue());
} else if (obj.isDouble()) {
rowVector.add(obj.asDouble());
} else if (obj.isShort()) {
rowVector.add(obj.shortValue());
} else if (obj.isFloat()) {
rowVector.add(obj.floatValue());
} else {
rowVector.add(obj);
}
break;
default:
rowVector.add(obj);
}
}
}
values.add(rowVector);
}
rows = values;
} else {
rows = new ArrayList<>();
}
rowIterator = rows.iterator();
}