Hive13DdlGenerator extends DdlGenerator { public String escapeSingleQuotes(String string) { Pattern pattern = Pattern.compile("(?<!\\\\)(')"); Matcher matcher = pattern.matcher(string); StringBuffer stringBuffer = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(stringBuffer, matcher.group(1).replace("'", "\\\\'")); } matcher.appendTail(stringBuffer); return stringBuffer.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 testEscapeSingleQuotes() { LinkedHashMap<String, String> testVector = new LinkedHashMap<>(); testVector.put("some text without single quotes", "some text without single quotes"); testVector.put("'some \\'text\\' with single 'quotes'", "\\'some \\'text\\' with single \\'quotes\\'"); testVector.put("'", "\\'"); testVector.put("''''", "\\'\\'\\'\\'"); testVector.put("'", "\\'"); testVector.put("'\'\\'", "\\'\\'\\'"); for (Object set : testVector.entrySet()) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) set; assertEquals(entry.getValue(), hive13DdlGenerator.escapeSingleQuotes((String) entry.getKey())); } }