Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HdfsStorageDescriptorTest.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.catalog;
16 
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.fail;
20 
21 import java.util.HashMap;
22 import java.util.List;
23 
24 import org.apache.hadoop.hive.metastore.api.SerDeInfo;
25 import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
26 import org.apache.hadoop.hive.serde.serdeConstants;
27 import org.junit.Test;
28 
30 import com.cloudera.impala.thrift.THdfsFileFormat;
31 import com.google.common.collect.ImmutableList;
32 
34  @Test
35  public void delimitersInCorrectOrder() {
36  final List<String> DELIMITER_KEYS =
37  ImmutableList.of(serdeConstants.LINE_DELIM, serdeConstants.FIELD_DELIM,
38  serdeConstants.COLLECTION_DELIM, serdeConstants.MAPKEY_DELIM,
39  serdeConstants.ESCAPE_CHAR, serdeConstants.QUOTE_CHAR);
40 
41  assertEquals(DELIMITER_KEYS, HdfsStorageDescriptor.DELIMITER_KEYS);
42  }
43 
48  @Test
51  String[] parquetSerDe = new String[] {
52  "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe",
53  "parquet.hive.serde.ParquetHiveSerDe"};
54  String [] inputFormats = new String [] {
55  "com.cloudera.impala.hive.serde.ParquetInputFormat",
56  "parquet.hive.DeprecatedParquetInputFormat",
57  "parquet.hive.MapredParquetInputFormat",
58  "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat"};
59  String [] outputFormats = new String [] {
60  "com.cloudera.impala.hive.serde.ParquetOutputFormat",
61  "parquet.hive.DeprecatedParquetOutputFormat",
62  "parquet.hive.MapredParquetOutputFormat",
63  "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat"};
64 
65  for (String serDe: parquetSerDe) {
66  SerDeInfo serDeInfo = new SerDeInfo();
67  serDeInfo.setSerializationLib(serDe);
68  serDeInfo.setParameters(new HashMap<String, String>());
69  for (String inputFormat: inputFormats) {
70  for (String outputFormat: outputFormats) {
71  StorageDescriptor sd = new StorageDescriptor();
72  sd.setSerdeInfo(serDeInfo);
73  sd.setInputFormat(inputFormat);
74  sd.setOutputFormat(outputFormat);
75  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTblName", sd));
76  }
77  }
78  }
79  }
80 
85  @Test
87  StorageDescriptor sd = HiveStorageDescriptorFactory.createSd(THdfsFileFormat.TEXT,
89  sd.setParameters(new HashMap<String, String>());
90  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
91  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "-2");
92  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
93 
94  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
95  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "-128");
96  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
97 
98  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
99  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "127");
100  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
101 
102  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
103  sd.getSerdeInfo().putToParameters(serdeConstants.LINE_DELIM, "\001");
104  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
105 
106  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
107  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "|");
108  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
109 
110  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
111  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "\t");
112  assertNotNull(HdfsStorageDescriptor.fromStorageDescriptor("fakeTbl", sd));
113 
114  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
115  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "ab");
116  try {
117  HdfsStorageDescriptor.fromStorageDescriptor("fake", sd);
118  fail();
119  } catch (HdfsStorageDescriptor.InvalidStorageDescriptorException e) {
120  assertEquals("Invalid delimiter: 'ab'. Delimiter must be specified as a " +
121  "single character or as a decimal value in the range [-128:127]",
122  e.getMessage());
123  }
124 
125  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
126  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "128");
127  try {
128  HdfsStorageDescriptor.fromStorageDescriptor("fake", sd);
129  fail();
130  } catch (HdfsStorageDescriptor.InvalidStorageDescriptorException e) {
131  assertEquals("Invalid delimiter: '128'. Delimiter must be specified as a " +
132  "single character or as a decimal value in the range [-128:127]",
133  e.getMessage());
134  }
135 
136  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
137  sd.getSerdeInfo().putToParameters(serdeConstants.FIELD_DELIM, "\128");
138  try {
139  HdfsStorageDescriptor.fromStorageDescriptor("fake", sd);
140  fail();
141  } catch (HdfsStorageDescriptor.InvalidStorageDescriptorException e) {
142  assertEquals("Invalid delimiter: '\128'. Delimiter must be specified as a " +
143  "single character or as a decimal value in the range [-128:127]",
144  e.getMessage());
145  }
146 
147  sd.getSerdeInfo().setParameters(new HashMap<String,String>());
148  sd.getSerdeInfo().putToParameters(serdeConstants.LINE_DELIM, "-129");
149  try {
150  HdfsStorageDescriptor.fromStorageDescriptor("fake", sd);
151  fail();
152  } catch (HdfsStorageDescriptor.InvalidStorageDescriptorException e) {
153  assertEquals("Invalid delimiter: '-129'. Delimiter must be specified as a " +
154  "single character or as a decimal value in the range [-128:127]",
155  e.getMessage());
156  }
157  }
158 }
static final RowFormat DEFAULT_ROW_FORMAT
Definition: RowFormat.java:32
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
static HdfsStorageDescriptor fromStorageDescriptor(String tblName, StorageDescriptor sd)