Package org.apache.sqoop.lib
Class FieldFormatter
- java.lang.Object
-
- org.apache.sqoop.lib.FieldFormatter
-
public final class FieldFormatter extends java.lang.ObjectStatic helper class that will help format data with quotes and escape chars.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringescapeAndEnclose(java.lang.String str, DelimiterSet delimiters)Takes an input string representing the value of a field, encloses it in enclosing chars, and escapes any occurrences of such characters in the middle.static java.lang.StringhiveStringDropDelims(java.lang.String str, DelimiterSet delimiters)This drops all default Hive delimiters from the string and passes it on.static java.lang.StringhiveStringReplaceDelims(java.lang.String str, java.lang.String replacement, DelimiterSet delimiters)replace hive delimiters with a user-defined string passed to the --hive-delims-replacement option.
-
-
-
Method Detail
-
hiveStringDropDelims
public static java.lang.String hiveStringDropDelims(java.lang.String str, DelimiterSet delimiters)This drops all default Hive delimiters from the string and passes it on. These delimiters are \n, \r and \01. This method is invoked when the command line option--hive-drop-delimsis provided.- Parameters:
str-delimiters-- Returns:
-
hiveStringReplaceDelims
public static java.lang.String hiveStringReplaceDelims(java.lang.String str, java.lang.String replacement, DelimiterSet delimiters)replace hive delimiters with a user-defined string passed to the --hive-delims-replacement option.- Parameters:
str-delimiters-- Returns:
-
escapeAndEnclose
public static java.lang.String escapeAndEnclose(java.lang.String str, DelimiterSet delimiters)Takes an input string representing the value of a field, encloses it in enclosing chars, and escapes any occurrences of such characters in the middle. The escape character itself is also escaped if it appears in the text of the field. If there is no enclosing character, then any delimiters present in the field body are escaped instead. The field is enclosed only if: enclose != '\000', and: encloseRequired is true, or one of the fields-terminated-by or lines-terminated-by characters is present in the string. Escaping is not performed if the escape char is '\000'.- Parameters:
str- - The user's string to escape and enclosedelimiters- - The DelimiterSet to use identifying the escape and enclose semantics. If the specified escape or enclose characters are '\000', those operations are not performed.- Returns:
- the escaped, enclosed version of 'str'.
-
-