final String processed = catalogTableUri.replaceAll(DOLLAR_EXPR_START_REGEX, DOLLAR_EXPR_START_NORMALIZED)
.replaceAll("}", EXPR_CLOSE_NORMALIZED);
URI tableUri = new URI(processed);
if (!"catalog".equals(tableUri.getScheme())) {
throw new URISyntaxException(tableUri.toString(), "catalog scheme is missing");
}
final String schemeSpecificPart = tableUri.getSchemeSpecificPart();
if (schemeSpecificPart == null) {
throw new URISyntaxException(tableUri.toString(), "Database and Table are missing");
}
String[] paths = schemeSpecificPart.split(INPUT_PATH_SEPARATOR);
if (paths.length != 2) {
throw new URISyntaxException(tableUri.toString(), "URI path is not in expected format: database:table");
}
database = paths[0];
table = paths[1];
if (database == null || database.length() == 0) {
throw new URISyntaxException(tableUri.toString(), "DB name is missing");
}
if (table == null || table.length() == 0) {
throw new URISyntaxException(tableUri.toString(), "Table name is missing");
}
String partRaw = tableUri.getFragment();
if (partRaw == null || partRaw.length() == 0) {
throw new URISyntaxException(tableUri.toString(), "Partition details are missing");
}
final String rawPartition = partRaw.replaceAll(DOLLAR_EXPR_START_NORMALIZED, DOLLAR_EXPR_START_REGEX)
.replaceAll(EXPR_CLOSE_NORMALIZED, EXPR_CLOSE_REGEX);
partitions = new LinkedHashMap<String, String>(); // preserve insertion order
String[] parts = rawPartition.split(PARTITION_SEPARATOR);
for (String part : parts) {
if (part == null || part.length() == 0) {
continue;
}
String[] keyVal = part.split(PARTITION_KEYVAL_SEPARATOR);
if (keyVal.length != 2) {
throw new URISyntaxException(tableUri.toString(),
"Partition key value pair is not specified properly in (" + part + ")");
}
partitions.put(keyVal[0], keyVal[1]);
}