@Override
  public void initialize(Configuration configuration, Properties tableProperties, Properties partitionProperties)
      throws SerDeException {
   super.initialize(configuration, tableProperties, partitionProperties);

   numColumns = this.getColumnNames().size();

   // Read the configuration parameters
   inputRegex = properties.getProperty(INPUT_REGEX);
   outputFormatString = properties.getProperty(OUTPUT_FORMAT_STRING);
   boolean inputRegexIgnoreCase = "true".equalsIgnoreCase(properties
       .getProperty(INPUT_REGEX_CASE_SENSITIVE));

   // Parse the configuration parameters
   if (inputRegex != null) {
     inputPattern = Pattern.compile(inputRegex, Pattern.DOTALL
         + (inputRegexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
   } else {
     inputPattern = null;
   }

    // All columns have to be of type STRING
   int i = 0;
   for (TypeInfo type : getColumnTypes()) {
     if (!type.equals(TypeInfoFactory.stringTypeInfo)) {
       throw new SerDeException(getClass().getName() + " only accepts string columns, but column[" + i + "] named "
           + getColumnNames().get(i) + " has type " + type);
     }
     i++;
   }

   // Constructing the row ObjectInspector:
   // The row consists of some string columns, each column will be a java
   // String object.
    List<ObjectInspector> columnOIs =
        Collections.nCopies(numColumns, PrimitiveObjectInspectorFactory.javaStringObjectInspector);

   // StandardStruct uses ArrayList to store the row.
    rowOI = ObjectInspectorFactory.getStandardStructObjectInspector(getColumnNames(), columnOIs);

   // Constructing the row object, etc, which will be reused for all rows.
   row = new ArrayList<>(Collections.nCopies(numColumns, null));
   outputFields = new Object[numColumns];
   outputRowText = new Text();
  }
RegexSerDe uses regular expression (regex) to serialize/deserialize.

It can deserialize the data using regex and extracts groups as columns. It
can also serialize the row object using a format string.

In deserialization stage, if a row does not match the regex, then all columns
in the row will be NULL. If a row matches the regex but has less than
expected groups, the missing groups will be NULL. If a row matches the regex
but has more than expected groups, the additional groups are just ignored.

In serialization stage, it uses java string formatter to format the columns
into a row. If the output type of the column in a query is not a string, it
will be automatically converted to String by Hive.

For the format of the format String, please refer to link: http
://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax

NOTE: Obviously, all columns have to be strings. Users can use
"CAST(a AS INT)" to convert columns to other types.

NOTE: This implementation is using String, and javaStringObjectInspector. A
more efficient implementation should use UTF-8 encoded Text and
writableStringObjectInspector. We should switch to that when we have a UTF-8
based Regex library.
contrib/src/java/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java