-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #176: add decimal format cast in hive
- Loading branch information
1 parent
8fee28c
commit 811feae
Showing
13 changed files
with
227 additions
and
85 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
49 changes: 49 additions & 0 deletions
49
...jdbc-adapter/src/main/java/com/exasol/adapter/dialects/hive/HiveColumnMetadataReader.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,49 @@ | ||
package com.exasol.adapter.dialects.hive; | ||
|
||
import com.exasol.adapter.*; | ||
import com.exasol.adapter.dialects.*; | ||
import com.exasol.adapter.jdbc.*; | ||
import com.exasol.adapter.metadata.*; | ||
|
||
import java.sql.*; | ||
|
||
import static com.exasol.adapter.dialects.hive.HiveProperties.HIVE_CAST_NUMBER_TO_DECIMAL_PROPERTY; | ||
|
||
/** | ||
* This class implements Hive-specific reading of column metadata. | ||
*/ | ||
public class HiveColumnMetadataReader extends BaseColumnMetadataReader { | ||
|
||
/** | ||
* Create a new instance of the {@link HiveColumnMetadataReader}. | ||
* | ||
* @param connection connection to the remote data source | ||
* @param properties user-defined adapter properties | ||
* @param identifierConverter converter between source and Exasol identifiers | ||
*/ | ||
public HiveColumnMetadataReader(final Connection connection, final AdapterProperties properties, | ||
final IdentifierConverter identifierConverter) { | ||
super(connection, properties, identifierConverter); | ||
} | ||
|
||
@Override | ||
public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) { | ||
if (jdbcTypeDescription.getJdbcType() == Types.DECIMAL) { | ||
return mapDecimal(jdbcTypeDescription); | ||
} else { | ||
return super.mapJdbcType(jdbcTypeDescription); | ||
} | ||
} | ||
|
||
protected DataType mapDecimal(final JdbcTypeDescription jdbcTypeDescription) { | ||
final int jdbcPrecision = jdbcTypeDescription.getPrecisionOrSize(); | ||
final int scale = jdbcTypeDescription.getDecimalScale(); | ||
if (jdbcPrecision <= DataType.MAX_EXASOL_DECIMAL_PRECISION) { | ||
return DataType.createDecimal(jdbcPrecision, scale); | ||
} else if (this.properties.containsKey(HIVE_CAST_NUMBER_TO_DECIMAL_PROPERTY)) { | ||
return getNumberTypeFromProperty(HIVE_CAST_NUMBER_TO_DECIMAL_PROPERTY); | ||
} else { | ||
return DataType.createMaximumSizeVarChar(DataType.ExaCharset.UTF8); | ||
} | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...ualschema-jdbc-adapter/src/main/java/com/exasol/adapter/dialects/hive/HiveProperties.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,12 @@ | ||
package com.exasol.adapter.dialects.hive; | ||
|
||
/** | ||
* This class contains HIVE-specific adapter properties. | ||
*/ | ||
public final class HiveProperties { | ||
public static final String HIVE_CAST_NUMBER_TO_DECIMAL_PROPERTY = "HIVE_CAST_NUMBER_TO_DECIMAL_WITH_PRECISION_AND_SCALE"; | ||
|
||
private HiveProperties() { | ||
// prevent instantiation | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...-adapter/src/test/java/com/exasol/adapter/dialects/hive/HiveColumnMetadataReaderTest.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,37 @@ | ||
package com.exasol.adapter.dialects.hive; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.*; | ||
|
||
import java.sql.*; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
import com.exasol.adapter.*; | ||
import com.exasol.adapter.dialects.*; | ||
import com.exasol.adapter.metadata.*; | ||
|
||
class HiveColumnMetadataReaderTest { | ||
private HiveColumnMetadataReader columnMetadataReader; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
this.columnMetadataReader = new HiveColumnMetadataReader(null, AdapterProperties.emptyProperties(), | ||
BaseIdentifierConverter.createDefault()); | ||
} | ||
|
||
@Test | ||
void mapDecimalReturnDecimal() { | ||
final JdbcTypeDescription typeDescription = new JdbcTypeDescription(Types.DECIMAL, 0, | ||
DataType.MAX_EXASOL_DECIMAL_PRECISION, 10, "DECIMAL"); | ||
assertThat(columnMetadataReader.mapJdbcType(typeDescription), equalTo(DataType.createDecimal(36, 0))); | ||
} | ||
|
||
@Test | ||
void mapDecimalReturnVarchar() { | ||
final JdbcTypeDescription typeDescription = new JdbcTypeDescription(Types.DECIMAL, 0, | ||
DataType.MAX_EXASOL_DECIMAL_PRECISION + 1, 10, "DECIMAL"); | ||
assertThat(columnMetadataReader.mapJdbcType(typeDescription), | ||
equalTo(DataType.createMaximumSizeVarChar(DataType.ExaCharset.UTF8))); | ||
} | ||
} |
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
Oops, something went wrong.