Skip to content

Commit

Permalink
updated code mappings to comport with latest findings
Browse files Browse the repository at this point in the history
  • Loading branch information
gneeri committed Nov 25, 2024
1 parent 40b0f4e commit 132b07c
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions ndc-cli/src/main/kotlin/io/hasura/cli/PhoenixConfigGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,37 @@ import java.sql.Types
object PhoenixConfigGenerator : IConfigGenerator {


private fun translatePhoenixDataTypeToSqlType(phoenixDataType: Int, isThinClient: Boolean = true): String {
private fun translatePhoenixDataTypeToSqlType(phoenixDataType: Int?, isThinClient: Boolean = true): String {

val sqlType = if (!isThinClient) {
phoenixDataType
phoenixDataType ?: Types.OTHER
} else {
when (phoenixDataType) {
0 -> Types.TINYINT // UNSIGNED_TINYINT
1 -> Types.SMALLINT // UNSIGNED_SMALLINT
2 -> Types.INTEGER // UNSIGNED_INT
3 -> Types.BIGINT // UNSIGNED_LONG
4 -> Types.FLOAT // UNSIGNED_FLOAT
5 -> Types.DOUBLE // UNSIGNED_DOUBLE
6 -> Types.BINARY // BINARY
7 -> Types.CHAR // CHAR
8 -> Types.VARCHAR // VARCHAR
9 -> Types.VARBINARY // VARBINARY
10 -> Types.DECIMAL // DECIMAL
11 -> Types.TIMESTAMP // TIMESTAMP
12 -> Types.DATE // DATE
13 -> Types.TIME // TIME
14 -> Types.TIME // UNSIGNED_TIME
15 -> Types.DATE // UNSIGNED_DATE
16 -> Types.TIMESTAMP // UNSIGNED_TIMESTAMP
17 -> Types.ARRAY // ARRAY
18 -> Types.BOOLEAN // BOOLEAN
19 -> Types.TINYINT // TINYINT
20 -> Types.SMALLINT // SMALLINT
21 -> Types.INTEGER // INTEGER
22 -> Types.BIGINT // BIGINT
23 -> Types.FLOAT // FLOAT
24 -> Types.DOUBLE // DOUBLE
25 -> Types.ARRAY // UNSIGNED_ARRAY
26 -> Types.BINARY // UUID
null -> Types.OTHER // Handle null data_type
-6 -> Types.TINYINT // TINYINT
-5 -> Types.BIGINT // BIGINT
-3 -> Types.VARBINARY // VARBINARY
-2 -> Types.BINARY // BINARY
1 -> Types.CHAR // CHAR
3 -> Types.DECIMAL // DECIMAL
4 -> Types.INTEGER // INTEGER
5 -> Types.SMALLINT // SMALLINT
6 -> Types.FLOAT // FLOAT
8 -> Types.DOUBLE // DOUBLE
9 -> Types.VARCHAR // VARCHAR
10 -> Types.SMALLINT // UNSIGNED_SMALLINT (maps to SMALLINT)
11 -> Types.FLOAT // UNSIGNED_FLOAT (maps to FLOAT)
12 -> Types.VARCHAR // VARCHAR (Phoenix specific)
13 -> Types.VARCHAR // (Custom/Unsupported, mapped to VARCHAR)
14 -> Types.VARCHAR // (Custom/Unsupported, mapped to VARCHAR)
15 -> Types.VARCHAR // (Custom/Unsupported, mapped to VARCHAR)
16 -> Types.BOOLEAN // BOOLEAN
18 -> Types.ARRAY // ARRAY
19 -> Types.VARBINARY // VARBINARY (Phoenix specific)
20 -> Types.VARBINARY // VARBINARY (Phoenix specific)
91 -> Types.DATE // DATE
92 -> Types.TIME // TIME
93 -> Types.TIMESTAMP // TIMESTAMP
else ->
if (JDBCType.valueOf(phoenixDataType) != null) {
phoenixDataType
Expand All @@ -63,10 +61,12 @@ object PhoenixConfigGenerator : IConfigGenerator {

val isThinClient = jdbcUrl.contains("phoenix:thin", ignoreCase = true)

val result = ctx.fetch("""
val result = ctx.fetch(
"""
SELECT * FROM SYSTEM.CATALOG
WHERE TABLE_SCHEM != 'SYSTEM' OR TABLE_SCHEM IS NULL
""")
"""
)

val groupedBySchema = result.groupBy { it["TABLE_SCHEM"] as String? }

Expand All @@ -82,7 +82,7 @@ object PhoenixConfigGenerator : IConfigGenerator {
ColumnSchemaRow(
name = if (columnFamily != null && columnFamily != "0") "$columnFamily.$columnName" else columnName,
description = null,
type = translatePhoenixDataTypeToSqlType(it["DATA_TYPE"] as Int, isThinClient),
type = translatePhoenixDataTypeToSqlType(it["DATA_TYPE"] as? Int, isThinClient),
numeric_scale = null,
nullable = it["NULLABLE"] == 1,
auto_increment = it["IS_AUTOINCREMENT"] == "YES",
Expand All @@ -91,7 +91,7 @@ object PhoenixConfigGenerator : IConfigGenerator {
}

TableSchemaRow(
tableName = if (schema != null) "$schema.$tableName" else tableName,
tableName = if (schema != null) "$schema.$tableName" else tableName,
tableType = if (records.any { it["TABLE_TYPE"] == "u" }) TableType.TABLE else TableType.VIEW,
description = null,
columns = columns,
Expand Down

0 comments on commit 132b07c

Please sign in to comment.