forked from linkedin/transport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for getting field names (linkedin#140)
- Loading branch information
Showing
10 changed files
with
109 additions
and
14 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
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
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
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
34 changes: 34 additions & 0 deletions
34
...ortable-udfs-hive/src/test/java/com/linkedin/transport/hive/typesystem/TestHiveTypes.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,34 @@ | ||
/** | ||
* Copyright 2023 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.transport.hive.typesystem; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.transport.api.types.StdType; | ||
import com.linkedin.transport.hive.types.HiveStructType; | ||
import java.util.stream.Collectors; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; | ||
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class TestHiveTypes { | ||
|
||
@Test | ||
public void testStructType() { | ||
StructObjectInspector structObjectInspector = ObjectInspectorFactory.getStandardStructObjectInspector( | ||
ImmutableList.of("fieldOne", "fieldTwo"), | ||
ImmutableList.of(PrimitiveObjectInspectorFactory.javaIntObjectInspector, | ||
PrimitiveObjectInspectorFactory.javaDoubleObjectInspector)); | ||
HiveStructType hiveStructType = new HiveStructType(structObjectInspector); | ||
// Field names are case-insensitive | ||
Assert.assertEquals(hiveStructType.fieldNames(), ImmutableList.of("fieldone", "fieldtwo")); | ||
Assert.assertEquals(hiveStructType.fieldTypes().stream().map(StdType::underlyingType).collect(Collectors.toList()), | ||
ImmutableList.of(PrimitiveObjectInspectorFactory.javaIntObjectInspector, | ||
PrimitiveObjectInspectorFactory.javaDoubleObjectInspector)); | ||
} | ||
} |
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
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
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
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
30 changes: 30 additions & 0 deletions
30
transportable-udfs-trino/src/test/java/com/linkedin/transport/trino/TestTrinoTypes.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,30 @@ | ||
/** | ||
* Copyright 2023 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.transport.trino; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.transport.api.types.StdType; | ||
import com.linkedin.transport.trino.types.TrinoStructType; | ||
import io.trino.spi.type.BigintType; | ||
import io.trino.spi.type.DoubleType; | ||
import io.trino.spi.type.RowType; | ||
import java.util.stream.Collectors; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class TestTrinoTypes { | ||
|
||
@Test | ||
public void testStructType() { | ||
RowType.Field field1 = RowType.field("fieldOne", BigintType.BIGINT); | ||
RowType.Field field2 = RowType.field("fieldTwo", DoubleType.DOUBLE); | ||
TrinoStructType trinoStructType = new TrinoStructType(RowType.rowType(field1, field2)); | ||
Assert.assertEquals(trinoStructType.fieldNames(), ImmutableList.of("fieldOne", "fieldTwo")); | ||
Assert.assertEquals(trinoStructType.fieldTypes().stream().map(StdType::underlyingType).collect(Collectors.toList()), | ||
ImmutableList.of(BigintType.BIGINT, DoubleType.DOUBLE)); | ||
} | ||
} |