Hive13DdlGenerator extends DdlGenerator { public String getHivePathRegex(List<SchemaColumn> partitionColumns) { StringBuilder sb = new StringBuilder(26); sb.append("^(?:"); for (SchemaColumn partitionColumn : partitionColumns) { sb.append("(?:"); sb.append("(?:"); sb.append("\\/"); sb.append('|'); sb.append(REGEX_S3_EMPTY_PARTITION); sb.append(')'); sb.append('|'); sb.append("(?:"); sb.append("\\/"); sb.append("(?:"); sb.append("(?i)"); sb.append(Matcher.quoteReplacement(partitionColumn.getName())); sb.append('|'); sb.append(Matcher.quoteReplacement(partitionColumn.getName().replace("_", "-"))); sb.append(')'); sb.append("=([^/]+)"); } sb.append("("); sb.append("\\/"); sb.append("[^/]*"); sb.append('|'); sb.append(REGEX_S3_EMPTY_PARTITION); sb.append(")"); for (int i = 0; i < 2 * partitionColumns.size(); i++) { sb.append(')'); } sb.append(')'); sb.append('$'); return sb.toString(); }  String escapeSingleQuotes(String string); @Override String generateCreateTableDdl(BusinessObjectDataDdlRequest request, BusinessObjectFormatEntity businessObjectFormatEntity,
        CustomDdlEntity customDdlEntity, List<String> storageNames, List<StorageEntity> requestedStorageEntities,
        Map<String, StorageEntity> cachedStorageEntities, Map<String, String> cachedS3BucketNames); @Override String generateCreateTableDdl(BusinessObjectFormatDdlRequest request, BusinessObjectFormatEntity businessObjectFormatEntity,
        CustomDdlEntity customDdlEntity); @Override String generateReplaceColumnsStatement(BusinessObjectFormatDdlRequest request, BusinessObjectFormatEntity businessObjectFormatEntity); String getDdlCharacterValue(String string); String getDdlCharacterValue(String string, boolean escapeSingleBackslash); @Override BusinessObjectDataDdlOutputFormatEnum getDdlOutputFormat(); List<HivePartitionDto> getHivePartitions(BusinessObjectDataKey businessObjectDataKey, List<SchemaColumn> autoDiscoverableSubPartitionColumns,
        String s3KeyPrefix, Collection<String> storageFiles, String storageName); Pattern getHivePathPattern(List<SchemaColumn> partitionColumns); String getHivePathRegex(List<SchemaColumn> partitionColumns); static final String NO_PARTITIONING_PARTITION_KEY; static final String NO_PARTITIONING_PARTITION_VALUE; static final String ORC_HIVE_FILE_FORMAT; static final String PARQUET_HIVE_FILE_FORMAT; static final String TEXT_HIVE_FILE_FORMAT; static final String JSON_HIVE_FILE_FORMAT; static final String REGEX_S3_EMPTY_PARTITION; }
@Test public void testGetHivePathRegex() { List<String> expectedRegularExpressions = Arrays .asList("^(?:(\\/[^/]*|_\\$folder\\$))$", "^(?:(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_1|Column-1)=([^/]+)(\\/[^/]*|_\\$folder\\$))))$", "^(?:(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_1|Column-1)=([^/]+)(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_2|Column-2)=([^/]+)" + "(\\/[^/]*|_\\$folder\\$))))))$", "^(?:(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_1|Column-1)=([^/]+)(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_2|Column-2)=([^/]+)" + "(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_3|Column-3)=([^/]+)(\\/[^/]*|_\\$folder\\$))))))))$", "^(?:(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_1|Column-1)=([^/]+)(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_2|Column-2)=([^/]+)" + "(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_3|Column-3)=([^/]+)(?:(?:\\/|_\\$folder\\$)|(?:\\/(?:(?i)Column_4|Column-4)=([^/]+)" + "(\\/[^/]*|_\\$folder\\$))))))))))$"); assertEquals(expectedRegularExpressions.get(0), hive13DdlGenerator.getHivePathRegex(new ArrayList<>())); assertEquals(expectedRegularExpressions.get(1), hive13DdlGenerator.getHivePathRegex(getPartitionColumns(Collections.singletonList("Column_1")))); assertEquals(expectedRegularExpressions.get(2), hive13DdlGenerator.getHivePathRegex(getPartitionColumns(Arrays.asList("Column_1", "Column_2")))); assertEquals(expectedRegularExpressions.get(3), hive13DdlGenerator.getHivePathRegex(getPartitionColumns(Arrays.asList("Column_1", "Column_2", "Column_3")))); assertEquals(expectedRegularExpressions.get(4), hive13DdlGenerator.getHivePathRegex(getPartitionColumns(Arrays.asList("Column_1", "Column_2", "Column_3", "Column_4")))); }