-
Notifications
You must be signed in to change notification settings - Fork 40
Fixed getColumns function to return correct output for complex datatypes #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
77711d8
40d7a14
4effebb
0e3beb9
647a163
52eda8a
87e2ea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,14 +184,20 @@ List<List<Object>> getRows( | |
| if (typeVal == null) { // safety check | ||
| object = null; | ||
| } else { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| // Check if complex datatype support is disabled and this is a complex type | ||
| if (!ctx.isComplexDatatypeSupportEnabled() && isComplexType(typeVal)) { | ||
| object = Types.VARCHAR; | ||
| } else { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } | ||
| } | ||
| break; | ||
| case "SQL_DATETIME_SUB": | ||
| // check if typeVal is a date/time related field | ||
| if (typeVal != null | ||
| && (typeVal.contains(DATE_TYPE) || typeVal.contains(TIMESTAMP_TYPE))) { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| && (stripBaseTypeName(typeVal).contains(DATE_TYPE) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| || stripBaseTypeName(typeVal).contains(TIMESTAMP_TYPE))) { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } else { | ||
| object = null; | ||
| } | ||
|
|
@@ -218,7 +224,11 @@ List<List<Object>> getRows( | |
| } | ||
| } catch (SQLException e) { | ||
| if (mappedColumn.getColumnName().equals(DATA_TYPE_COLUMN.getColumnName())) { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| if (!ctx.isComplexDatatypeSupportEnabled() && isComplexType(typeVal)) { | ||
| object = Types.VARCHAR; | ||
| } else { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } | ||
| } else if (mappedColumn | ||
| .getColumnName() | ||
| .equals(CHAR_OCTET_LENGTH_COLUMN.getColumnName())) { | ||
|
|
@@ -252,11 +262,12 @@ List<List<Object>> getRows( | |
| if (mappedColumn.getColumnName().equals(COLUMN_TYPE_COLUMN.getColumnName())) { | ||
| if (typeVal != null | ||
| && (typeVal.contains(ARRAY_TYPE) | ||
| || typeVal.contains(MAP_TYPE) | ||
| || typeVal.contains( | ||
| MAP_TYPE))) { // for complex data types, do not strip type name | ||
| STRUCT_TYPE))) { // for complex data types, do not strip type name | ||
| object = typeVal; | ||
| } else { | ||
| object = stripTypeName(typeVal); | ||
| object = stripBaseTypeName(typeVal); | ||
| } | ||
| } | ||
| // Set COLUMN_SIZE to 255 if it's not present | ||
|
|
@@ -339,7 +350,7 @@ int getColumnSize(String typeVal) { | |
| if (isTextType(typeVal)) { | ||
| return ctx.getDefaultStringColumnLength(); | ||
| } | ||
| String typeName = stripTypeName(typeVal); | ||
| String typeName = stripBaseTypeName(typeVal); | ||
| switch (typeName) { | ||
| case "DECIMAL": | ||
| case "NUMERIC": | ||
|
|
@@ -403,13 +414,13 @@ int getBufferLength(String typeVal) { | |
| if (typeVal == null || typeVal.isEmpty()) { | ||
| return 0; | ||
| } | ||
| if (typeVal.contains("ARRAY") || typeVal.contains("MAP")) { | ||
| if (typeVal.contains("ARRAY") || typeVal.contains("MAP") || typeVal.contains("STRUCT")) { | ||
| return 255; | ||
| } | ||
| if (isTextType(typeVal)) { | ||
| return getColumnSize(typeVal); | ||
| } | ||
| int sqlType = getCode(stripTypeName(typeVal)); | ||
| int sqlType = getCode(stripBaseTypeName(typeVal)); | ||
| return getSizeInBytes(sqlType); | ||
| } | ||
|
|
||
|
|
@@ -480,6 +491,22 @@ public String stripBaseTypeName(String typeName) { | |
| return typeName; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the given type string represents a complex type (ARRAY, MAP, or STRUCT). | ||
| * | ||
| * @param typeVal The type string to check | ||
| * @return true if the type is a complex type, false otherwise | ||
| */ | ||
| private boolean isComplexType(String typeVal) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what abt variant?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since variant is not a complex type so we do not need to handle it differently |
||
| if (typeVal == null) { | ||
| return false; | ||
| } | ||
| String baseType = stripBaseTypeName(typeVal); | ||
| return baseType.contains(ARRAY_TYPE) | ||
| || baseType.contains(MAP_TYPE) | ||
| || baseType.contains(STRUCT_TYPE); | ||
| } | ||
|
|
||
| int getCode(String s) { | ||
| switch (s) { | ||
| case "STRING": | ||
|
|
@@ -809,30 +836,36 @@ List<List<Object>> getThriftRows(List<List<Object>> rows, List<ResultColumn> col | |
| List<List<Object>> updatedRows = new ArrayList<>(); | ||
| for (List<Object> row : rows) { | ||
| List<Object> updatedRow = new ArrayList<>(); | ||
| String typeVal = null; | ||
| int col_type_index = columns.indexOf(COLUMN_TYPE_COLUMN); // only relevant for getColumns | ||
| if (col_type_index != -1) { | ||
| typeVal = (String) row.get(col_type_index); | ||
| } | ||
| for (ResultColumn column : columns) { | ||
| if (NULL_COLUMN_COLUMNS.contains(column) || NULL_TABLE_COLUMNS.contains(column)) { | ||
| updatedRow.add(null); | ||
| continue; | ||
| } | ||
| Object object; | ||
| String typeVal = null; | ||
| int col_type_index = columns.indexOf(COLUMN_TYPE_COLUMN); // only relevant for getColumns | ||
| if (col_type_index != -1) { | ||
| typeVal = (String) row.get(col_type_index); | ||
| } | ||
| switch (column.getColumnName()) { | ||
| case "SQL_DATA_TYPE": | ||
| if (typeVal == null) { // safety check | ||
| object = null; | ||
| } else { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| // Check if complex datatype support is disabled and this is a complex type | ||
| if (!ctx.isComplexDatatypeSupportEnabled() && isComplexType(typeVal)) { | ||
| object = Types.VARCHAR; | ||
| } else { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } | ||
| } | ||
| break; | ||
| case "SQL_DATETIME_SUB": | ||
| // check if typeVal is a date/time related field | ||
| if (typeVal != null | ||
| && (typeVal.contains(DATE_TYPE) || typeVal.contains(TIMESTAMP_TYPE))) { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| && (stripBaseTypeName(typeVal).contains(DATE_TYPE) | ||
| || stripBaseTypeName(typeVal).contains(TIMESTAMP_TYPE))) { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } else { | ||
| object = null; | ||
| } | ||
|
|
@@ -870,7 +903,12 @@ List<List<Object>> getThriftRows(List<List<Object>> rows, List<ResultColumn> col | |
| } | ||
| } | ||
| if (column.getColumnName().equals(DATA_TYPE_COLUMN.getColumnName())) { | ||
| object = getCode(stripTypeName(typeVal)); | ||
| // Check if complex datatype support is disabled and this is a complex type | ||
| if (!ctx.isComplexDatatypeSupportEnabled() && isComplexType(typeVal)) { | ||
| object = Types.VARCHAR; | ||
| } else { | ||
| object = getCode(stripBaseTypeName(typeVal)); | ||
| } | ||
| } | ||
| if (column.getColumnName().equals(CHAR_OCTET_LENGTH_COLUMN.getColumnName())) { | ||
| object = getCharOctetLength(typeVal); | ||
|
|
@@ -889,10 +927,12 @@ List<List<Object>> getThriftRows(List<List<Object>> rows, List<ResultColumn> col | |
| // Handle TYPE_NAME separately for potential modifications | ||
| if (column.getColumnName().equals(COLUMN_TYPE_COLUMN.getColumnName())) { | ||
| if (typeVal != null | ||
| && (typeVal.contains(ARRAY_TYPE) || typeVal.contains(MAP_TYPE))) { | ||
| && (typeVal.contains(ARRAY_TYPE) | ||
| || typeVal.contains(MAP_TYPE) | ||
| || typeVal.contains(STRUCT_TYPE))) { | ||
| object = typeVal; | ||
| } else { | ||
| object = stripTypeName(typeVal); | ||
| object = stripBaseTypeName(typeVal); | ||
| } | ||
| } | ||
| // Set COLUMN_SIZE to 255 if it's not present | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is changing
stripTypeNametostripBaseTypeNamefixing exactly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to change for thrift resultsetmetadata?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now instead of returning
array<INT>it'll simply return the base type that is array.For thrift, it uses another method but the behaviour is same for that as well.