hive 表的一些默认值

见 Hadoop.The.Definitive.Guide.2nd.Edition  P388

Thus, the statement:
    CREATE TABLE ...;
is identical to the more explicit:
    CREATE TABLE ...
    ROW FORMAT DELIMITED
         FIELDS TERMINATED BY '\001'
         COLLECTION ITEMS TERMINATED BY '\002'
         MAP KEYS TERMINATED BY '\003'
         LINES TERMINATED BY '\n'
    STORED AS TEXTFILE;

Notice that the octal form of the delimiter characters can be used—001 for Control-A, for instance.


STORED AS TEXTFILE 这个目前可以通过配置文件配置,配置项是hive.default.fileformat。
HiveConf
    // Default file format for CREATE TABLE statement
    // Options: TextFile, SequenceFile
    HIVEDEFAULTFILEFORMAT("hive.default.fileformat", "TextFile"),

其他诸如: FIELD_DELIM、COLLECTION_DELIM、MAPKEY_DELIM、SERIALIZATION_NULL_FORMAT目前无法通过配置文件进行配置:

以LazySimpleSerDe的为例来看:

public class LazySimpleSerDe implements SerDe {

    public static final byte[] DefaultSeparators = {(byte) 1, (byte) 2, (byte) 3};

      public static SerDeParameters initSerdeParams(Configuration job,
           Properties tbl, String serdeName) throws SerDeException {
        SerDeParameters serdeParams = new SerDeParameters();
        // Read the separators: We use 8 levels of separators by default, but we
        // should change this when we allow users to specify more than 10 levels
        // of separators through DDL.
        serdeParams.separators = new byte[8];
        serdeParams.separators[0] = getByte(tbl.getProperty(Constants.FIELD_DELIM,
           tbl.getProperty(Constants.SERIALIZATION_FORMAT)), DefaultSeparators[0]);
        serdeParams.separators[1] = getByte(tbl
           .getProperty(Constants.COLLECTION_DELIM), DefaultSeparators[1]);
        serdeParams.separators[2] = getByte(
           tbl.getProperty(Constants.MAPKEY_DELIM), DefaultSeparators[2]);
        for (int i = 3; i < serdeParams.separators.length; i++) {
              serdeParams.separators[i] = (byte) (i + 1);
        }

        serdeParams.nullString = tbl.getProperty(
             Constants.SERIALIZATION_NULL_FORMAT, "\\N");
        serdeParams.nullSequence = new Text(serdeParams.nullString);
  
    }
  
}

Constants:  public static final String SERIALIZATION_NULL_FORMAT = "serialization.null.format";
serialization.null.format默认为/N
^A为中间的分隔符也就是001
1^A/N
2^A/N
3^A3
4^A4
5^A5

    serdeParams.nullString = tbl.getProperty(
        Constants.SERIALIZATION_NULL_FORMAT, "\\N");
    早前的版本有个问题见:http://www.linezing.com/blog/?p=500,最新的版本已经修复了该问题。

ALTER TABLE ctas_null_format1 SET SERDEPROPERTIES ('serialization.null.format'='\\N');

你可能感兴趣的:(hive)