in spanner-data-validator-java/src/main/java/com/google/migration/TableSpecList.java [159:228]
public static List<TableSpec> getFromJsonString(String jsonStr) {
try {
JSONArray jsonarray = new JSONArray(jsonStr);
List<TableSpec> tableSpecs = new ArrayList<>();
for (int i = 0; i < jsonarray.length(); i++) {
TableSpec tableSpec = new TableSpec();
JSONObject jsonObject = jsonarray.getJSONObject(i);
tableSpec.setTableName(jsonObject.getString("tableName"));
tableSpec.setSourceQuery(jsonObject.getString("sourceQuery"));
tableSpec.setDestQuery(jsonObject.getString("destQuery"));
tableSpec.setRangeFieldIndex(jsonObject.getInt("rangeFieldIndex"));
tableSpec.setRangeFieldType(jsonObject.getString("rangeFieldType"));
tableSpec.setRangeStart(jsonObject.getString("rangeStart"));
tableSpec.setRangeEnd(jsonObject.getString("rangeEnd"));
tableSpec.setRangeCoverage(
jsonObject.isNull("rangeCoverage") ?
BigDecimal.valueOf(100) :
jsonObject.getBigDecimal("rangeCoverage"));
tableSpec.setPartitionCount(
jsonObject.isNull("partitionCount") ?
100 :
jsonObject.getInt("partitionCount"));
tableSpec.setPartitionFilterRatio(
jsonObject.isNull("partitionFilterRatio") ?
-1 :
jsonObject.getInt("partitionFilterRatio"));
tableSpec.setTimestampThresholdColIndex(
jsonObject.isNull("timestampThresholdColIndex") ?
-1 :
jsonObject.getInt("timestampThresholdColIndex"));
tableSpec.setTimestampThresholdDeltaInMins(
jsonObject.isNull("timestampThresholdDeltaInMins") ?
0 :
jsonObject.getInt("timestampThresholdDeltaInMins"));
tableSpec.setTimestampThresholdZoneOffset(
jsonObject.isNull("timestampThresholdZoneOffset") ?
0 :
jsonObject.getInt("timestampThresholdZoneOffset"));
if(!jsonObject.isNull("timestampThresholdValue")) {
String rawVal = jsonObject.getString("timestampThresholdValue");
LocalDateTime dateTime = LocalDateTime.parse(rawVal);
Instant instant = dateTime.toInstant(ZoneOffset.ofHours(tableSpec.getTimestampThresholdZoneOffset()));
tableSpec.setTimestampThresholdValue(instant.toEpochMilli());
} else {
tableSpec.setTimestampThresholdValue(0L);
}
tableSpecs.add(tableSpec);
} // for
return tableSpecs;
} catch (Exception ex) {
LOG.error("Exception while loading table specs from json string");
LOG.error(ex.getMessage());
LOG.error(ex.getStackTrace().toString());
}
return null;
}