/** * Gets the DDL character value based on the specified configured character value. This method supports UTF-8 encoded strings and will "Hive" escape any * non-ASCII printable characters using '\(value)'. * * @param string the configured character value. * * @return the DDL character value. */ public String getDdlCharacterValue(String string) { return getDdlCharacterValue(string, false); }
/** * Gets the DDL character value based on the specified configured character value. This method supports UTF-8 encoded strings and will "Hive" escape any * non-ASCII printable characters using '\(value)'. * * @param string the configured character value. * * @return the DDL character value. */ public String getDdlCharacterValue(String string) { return getDdlCharacterValue(string, false); }
escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getDelimiter(), true)), StringUtils.isEmpty(generateDdlRequest.businessObjectFormatEntity.getEscapeCharacter()) ? "" : String.format(" ESCAPED BY '%s'", escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getEscapeCharacter(), true))))); String.format(" NULL DEFINED AS '%s'\n", escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getNullValue()))));
escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getDelimiter(), true)), StringUtils.isEmpty(generateDdlRequest.businessObjectFormatEntity.getEscapeCharacter()) ? "" : String.format(" ESCAPED BY '%s'", escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getEscapeCharacter(), true))))); String.format(" NULL DEFINED AS '%s'\n", escapeSingleQuotes(getDdlCharacterValue(generateDdlRequest.businessObjectFormatEntity.getNullValue()))));
@Test public void testGetDdlCharacterValueEscapeSingleBackslash() { assertEquals("\\", hive13DdlGenerator.getDdlCharacterValue("\\")); assertEquals("\\", hive13DdlGenerator.getDdlCharacterValue("\\", false)); assertEquals("\\\\", hive13DdlGenerator.getDdlCharacterValue("\\", true)); assertEquals("\\\\", hive13DdlGenerator.getDdlCharacterValue("\\\\", true)); }
@Test public void testGetDdlCharacterValueTwoNonAsciiPrintableChars() { // Decimal 128 is 200 in octal. assertEquals("\\200\\001", hive13DdlGenerator.getDdlCharacterValue(String.valueOf((char) 128) + String.valueOf((char) 1))); }
@Test public void testGetDdlCharacterValueAsciiNonAsciiMix() { // It makes no sense to output a single non-ASCII printable character in the middle of other ASCII printable characters, // but that's what we do if a user actually specifies this. We might want to add more validation to prevent this scenario in the future // since Hive shouldn't allow this. Please note that decimal 128 is 200 in octal. assertEquals("A\\200B", hive13DdlGenerator.getDdlCharacterValue("A" + String.valueOf((char) 128) + "B")); }
@Test public void testGetDdlCharacterValueLineFeed() { // Linefeed character is an ASCII octal \012 (decimal 10) which gets escaped as part of the DDL generation. assertEquals("\\012", hive13DdlGenerator.getDdlCharacterValue("\n")); }
@Test public void testGetDdlCharacterValueEmptyString() { assertEquals("", hive13DdlGenerator.getDdlCharacterValue("")); }
@Test public void testGetDdlCharacterValueAsciiPrintable() { assertEquals("|", hive13DdlGenerator.getDdlCharacterValue("|")); }