-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Enhancement] information_schema.COLUMNS support complex type #33431
Changes from all commits
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 |
---|---|---|
|
@@ -602,6 +602,7 @@ public String toSql(int depth) { | |
case DATETIME: | ||
case HLL: | ||
case BITMAP: | ||
case BINARY: | ||
case PERCENTILE: | ||
case JSON: | ||
case FUNCTION: | ||
|
@@ -845,4 +846,33 @@ public String canonicalName() { | |
return toString(); | ||
} | ||
} | ||
|
||
// This implementation is the same as BE schema_columns_scanner.cpp to_mysql_data_type_string | ||
public String toMysqlDataTypeString() { | ||
switch (type) { | ||
case BOOLEAN: | ||
return "tinyint"; | ||
case LARGEINT: | ||
return "bigint unsigned"; | ||
case DECIMAL32: | ||
case DECIMAL64: | ||
case DECIMAL128: | ||
case DECIMALV2: | ||
return "decimal"; | ||
default: | ||
return type.toString().toLowerCase(); | ||
} | ||
} | ||
|
||
// This implementation is the same as BE schema_columns_scanner.cpp type_to_string | ||
public String toMysqlColumnTypeString() { | ||
switch (type) { | ||
case BOOLEAN: | ||
return "tinyint(1)"; | ||
case LARGEINT: | ||
return "bigint(20) unsigned"; | ||
default: | ||
return toSql(); | ||
} | ||
} | ||
} | ||
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. The code is generally well written. It's formatted consistently with a lot of alignment, indicating it likely adheres to your style guide. There are a few suggestions that could help improve the code:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1776,4 +1776,14 @@ public static Type getInnermostType(Type type) throws AnalysisException { | |
public String canonicalName() { | ||
return toString(); | ||
} | ||
|
||
// This is used for information_schema.COLUMNS DATA_TYPE | ||
public String toMysqlDataTypeString() { | ||
return "unknown"; | ||
} | ||
|
||
// This is used for information_schema.COLUMNS COLUMN_TYPE | ||
public String toMysqlColumnTypeString() { | ||
return "unknown"; | ||
} | ||
} | ||
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. This review is based on the code snippet provided:
Again this review assumes absent elements such as exceptions handling etc., are handled elsewhere in your codebase. |
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.
The code changes appear correct and improve the program by checking if
dataType
orcolumnTypeStr
are set before attempting to use them. However, some improvements can be made to enhance readability, maintainability, and safety.Consider renaming
_desc_result
to something more descriptive that reflects what this variable holds.While it seems that the dereferenced values may not be null based on the given context, it would add robustness to your code to check for null references on
(*chunk)->get_column_by_slot_id(8)
and(*chunk)->get_column_by_slot_id(16)
calls.The
(void*)&value
style cast fromstd::string
tovoid*
isn't a good practice in modern C++. What you want to pass should be the internal char array of the string, so usevalue.c_str()
instead.Consider providing more explanation in their comments above each section of code. This makes it easier for others (and yourself in the future) to understand the purpose of this piece of code.
The block of code that extracts values out with the fall back to
to_mysql_data_type_string
/type_to_string
method for default value looks identical except for specific fields/accessors. This could potentially be abstracted into a function to comply with the DRY (Don't Repeat Yourself) principle.