-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIVE-28262:Single column use MultiDelimitSerDe parse column error
- Loading branch information
1 parent
73af4cd
commit 3cae7af
Showing
2 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyStruct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hive.serde2.lazy; | ||
|
||
import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyObjectInspectorParameters; | ||
import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyObjectInspectorParametersImpl; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo; | ||
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; | ||
import org.apache.hadoop.io.Text; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* TestLazyStruct.<br/> | ||
*/ | ||
public class TestLazyStruct { | ||
|
||
@Test | ||
public void testParseMultiDelimit() throws Throwable { | ||
try { | ||
// single field named id | ||
List<String> structFieldNames = new ArrayList<>(); | ||
structFieldNames.add("id"); | ||
// field type is string | ||
List<TypeInfo> fieldTypes = new ArrayList<>(); | ||
PrimitiveTypeInfo primitiveTypeInfo = new PrimitiveTypeInfo(); | ||
primitiveTypeInfo.setTypeName("string"); | ||
fieldTypes.add(primitiveTypeInfo); | ||
// separators + escapeChar => "|" | ||
byte[] separators = new byte[]{124, 2, 3, 4, 5, 6, 7, 8}; | ||
|
||
// sequence =>"\N" | ||
Text sequence = new Text(); | ||
sequence.set(new byte[]{92, 78}); | ||
|
||
// create lazy object inspector parameters | ||
LazyObjectInspectorParameters lazyObjectInspectorParameters = new LazyObjectInspectorParametersImpl(false, (byte) '0', | ||
false, null, separators, sequence); | ||
// create a lazy struct inspector | ||
ObjectInspector lazyStructInspector = LazyFactory.createLazyStructInspector(structFieldNames, fieldTypes, lazyObjectInspectorParameters); | ||
LazyStruct lazyStruct = (LazyStruct) LazyFactory.createLazyObject(lazyStructInspector); | ||
|
||
// origin row data | ||
String rowData = "1|@|"; | ||
// row field delimiter | ||
String fieldDelimiter = "|@|"; | ||
|
||
// parse row use multi delimit | ||
lazyStruct.parseMultiDelimit(rowData.getBytes(StandardCharsets.UTF_8), | ||
fieldDelimiter.getBytes(StandardCharsets.UTF_8)); | ||
|
||
// check the first field and second field start position index | ||
// before fix result: 0,1 | ||
// after fix result: 0,2 | ||
Assert.assertArrayEquals(new int[]{0, 2}, lazyStruct.startPosition); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
throw e; | ||
} | ||
|
||
} | ||
} |