15 package com.cloudera.impala.catalog;
17 import java.util.List;
20 import org.apache.hadoop.hive.metastore.api.SerDeInfo;
21 import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
22 import org.apache.hadoop.hive.serde.serdeConstants;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
27 import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.Maps;
48 serdeConstants.LINE_DELIM, serdeConstants.FIELD_DELIM,
49 serdeConstants.COLLECTION_DELIM, serdeConstants.MAPKEY_DELIM,
50 serdeConstants.ESCAPE_CHAR, serdeConstants.QUOTE_CHAR);
55 "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe",
56 "org.apache.hadoop.hive.serde2.avro.AvroSerDe",
57 "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe",
58 "parquet.hive.serde.ParquetHiveSerDe",
61 "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe");
63 private final static Logger
LOG = LoggerFactory.getLogger(HdfsStorageDescriptor.class);
91 Map<String, Byte> delimMap = Maps.newHashMap();
94 String delimValue = serdeInfo.getParameters().
get(delimKey);
95 if (delimValue == null) {
96 if (delimKey.equals(serdeConstants.FIELD_DELIM)) {
98 }
else if (delimKey.equals(serdeConstants.ESCAPE_CHAR)) {
100 }
else if (delimKey.equals(serdeConstants.LINE_DELIM)) {
103 delimMap.put(delimKey, delimMap.get(serdeConstants.FIELD_DELIM));
107 if (delimByteValue == null) {
109 delimValue +
"'. Delimiter must be specified as a single character or " +
110 "as a decimal value in the range [-128:127]");
112 delimMap.put(delimKey,
parseDelim(delimValue));
135 Preconditions.checkNotNull(delimVal);
139 return Byte.parseByte(delimVal);
140 }
catch (NumberFormatException e) {
141 if (delimVal.length() == 1)
return (byte) delimVal.charAt(0);
147 byte fieldDelim, byte collectionDelim, byte mapKeyDelim, byte escapeChar,
148 byte quoteChar,
int blockSize) {
149 this.fileFormat_ = fileFormat;
150 this.lineDelim_ = lineDelim;
151 this.fieldDelim_ = fieldDelim;
152 this.collectionDelim_ = collectionDelim;
153 this.mapKeyDelim_ = mapKeyDelim;
154 this.quoteChar_ = quoteChar;
155 this.blockSize_ = blockSize;
159 if (escapeChar == fieldDelim ||
160 escapeChar == lineDelim ||
161 escapeChar == collectionDelim) {
164 LOG.warn(
"Escape character for table, " + tblName +
" is set to "
165 +
"the same character as one of the delimiters. Ignoring escape character.");
167 this.escapeChar_ = escapeChar;
181 super(ex.getMessage(), ex);
196 StorageDescriptor sd)
201 "support tables of this type. REASON: SerDe library '%s' is not " +
202 "supported.", sd.getSerdeInfo().getSerializationLib()));
206 Map<String, String> parameters = sd.getSerdeInfo().getParameters();
208 String blockValue = parameters.get(
BLOCK_SIZE);
209 if (blockValue != null) {
210 blockSize = Integer.parseInt(blockValue);
216 delimMap.get(serdeConstants.LINE_DELIM),
217 delimMap.get(serdeConstants.FIELD_DELIM),
218 delimMap.get(serdeConstants.COLLECTION_DELIM),
219 delimMap.get(serdeConstants.MAPKEY_DELIM),
220 delimMap.get(serdeConstants.ESCAPE_CHAR),
221 delimMap.get(serdeConstants.QUOTE_CHAR),
223 }
catch (IllegalArgumentException ex) {
InvalidStorageDescriptorException(Exception ex)
HdfsFileFormat getFileFormat()
static final char DEFAULT_FIELD_DELIM
static final char DEFAULT_ESCAPE_CHAR
InvalidStorageDescriptorException(String msg, Throwable cause)
void setFileFormat(HdfsFileFormat fileFormat)
static final List< String > COMPATIBLE_SERDES
HdfsFileFormat fileFormat_
static final List< String > DELIMITER_KEYS
byte getCollectionDelim()
static final char DEFAULT_LINE_DELIM
static Byte parseDelim(String delimVal)
InvalidStorageDescriptorException(String s)
static Map< String, Byte > extractDelimiters(SerDeInfo serdeInfo)
static final String COMPRESSION
HdfsStorageDescriptor(String tblName, HdfsFileFormat fileFormat, byte lineDelim, byte fieldDelim, byte collectionDelim, byte mapKeyDelim, byte escapeChar, byte quoteChar, int blockSize)
static HdfsStorageDescriptor fromStorageDescriptor(String tblName, StorageDescriptor sd)
static final long serialVersionUID
static final String BLOCK_SIZE
final byte collectionDelim_