Skip to content
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

Merged
merged 2 commits into from
Oct 24, 2023
Merged

[Enhancement] information_schema.COLUMNS support complex type #33431

merged 2 commits into from
Oct 24, 2023

Conversation

Astralidea
Copy link
Contributor

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.2
    • 3.1
    • 3.0
    • 2.5

// This is used for information_schema.COLUMNS COLUMN_TYPE
public String toMysqlColumnTypeString() {
return "unknown";
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review is based on the code snippet provided:

  1. Comments: The comments should be more informative, describing not just where the methods are used but also what they do. E.g., // This method returns the MySQL data type string for information_schema.COLUMNS DATA_TYPE

  2. Constants: If "unknown" is a fallback value that could potentially be used in other places inside your codebase as well, consider making it a constant, e.g., public static final String UNKNOWN = "unknown";. Using a constant improves readability and makes your codebase easier to maintain.

  3. Method purpose: Right now both toMysqlDataTypeString() and toMysqlColumnTypeString() methods are returning "unknown". Without additional context, this suggests that either these methods aren't fully implemented yet or their purpose isn't clear. Before these methods get used, ensure they serve their intended purpose and update the return statement with proper dynamic values instead of a hardcoded "unknown".

  4. Unit Tests: These added methods should have corresponding unit tests that validate correct behavior.

  5. Follow Code Conventions: Depending on the codebase's established policies or the language style guide used (Java in this case), make sure you're consistent in following those conventions. For example, you'd typically find a single line between methods in most Java style guides.

Again this review assumes absent elements such as exceptions handling etc., are handled elsewhere in your codebase.

value = _desc_result.columns[_column_index].columnDesc.columnTypeStr;
} else {
value = type_to_string(_desc_result.columns[_column_index].columnDesc);
}
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value);
}
break;
Copy link

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 or columnTypeStr are set before attempting to use them. However, some improvements can be made to enhance readability, maintainability, and safety.

  1. Use meaningful variable names:

Consider renaming _desc_result to something more descriptive that reflects what this variable holds.

  1. Check for null pointers:

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.

  1. Avoid C-style casting of std::string in C++:

The (void*)&value style cast from std::string to void* isn't a good practice in modern C++. What you want to pass should be the internal char array of the string, so use value.c_str() instead.

  1. Extend the comments:

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.

  1. Code duplication:

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.

default:
return toSql();
}
}
}
Copy link

Choose a reason for hiding this comment

The 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:

  1. Handle enum type more explicitly: In both toMysqlDataTypeString() and toMysqlColumnTypeString() methods, you provided a 'default' case to handle all other types that are not explicitly called out. This loose handling might not always be best because if the internal implementation changes and extra types were added, they would all come into the 'default' branch thus possibly causing issues.

    default:
        return type.toString().toLowerCase();

    You could add an explicit handling for each known type and a default throw for unknown types.

  2. Use toString() directly in default case of new methods: You're calling .toLowerCase() on the enumeration name. The ENUM.name() method returns the name of this enum constant, exactly as declared in its enum declaration. So, the .toLowerCase() seems redundant unless there's a specific use-case to cover.

  3. Add comments to explain method logic and branches: Your existing comments are descriptive but don’t really describe what the method does or why certain steps are necessary within the function. They seem to reference another implementation spanning different files, which might raise maintainability concerns in the long run.

  4. Use of value-specific mappings: Depending on how complex your system is or can become, it may be more maintainable to use a Map to store these explicit conversions instead of a switch block.

  5. Unit tests: It's ideal to also include testing for these methods to ensure correctness and prevent potential regressions. If tests exist elsewhere, they should be updated to cover these changes too.

@Astralidea Astralidea enabled auto-merge (squash) October 23, 2023 09:04
Signed-off-by: Astralidea <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Oct 23, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@github-actions github-actions bot deleted a comment from wanpengfei-git Oct 23, 2023
@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 17 / 19 (89.47%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/catalog/Type.java 0 2 00.00% [1782, 1787]
🔵 com/starrocks/service/FrontendServiceImpl.java 2 2 100.00% []
🔵 com/starrocks/catalog/MapType.java 2 2 100.00% []
🔵 com/starrocks/catalog/StructType.java 2 2 100.00% []
🔵 com/starrocks/catalog/ArrayType.java 2 2 100.00% []
🔵 com/starrocks/catalog/ScalarType.java 9 9 100.00% []

@github-actions github-actions bot deleted a comment from wanpengfei-git Oct 23, 2023
@github-actions
Copy link

[BE Incremental Coverage Report]

fail : 6 / 8 (75.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exec/schema_scanner/schema_columns_scanner.cpp 6 8 75.00% [329, 431]

@Astralidea Astralidea merged commit a1a8427 into StarRocks:main Oct 24, 2023
41 of 43 checks passed
@github-actions
Copy link

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Oct 24, 2023
@github-actions
Copy link

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Oct 24, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

backport branch-3.2

✅ Backports have been created

@github-actions
Copy link

@Mergifyio backport branch-3.0

@github-actions github-actions bot removed the 3.0 label Oct 24, 2023
@github-actions
Copy link

@Mergifyio backport branch-2.5

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

backport branch-3.1

✅ Backports have been created

@github-actions github-actions bot removed the 2.5 label Oct 24, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

backport branch-3.0

✅ Backports have been created

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 24, 2023
mergify bot pushed a commit that referenced this pull request Oct 24, 2023
mergify bot pushed a commit that referenced this pull request Oct 24, 2023
mergify bot pushed a commit that referenced this pull request Oct 24, 2023
Signed-off-by: Astralidea <[email protected]>
(cherry picked from commit a1a8427)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/service/FrontendServiceImpl.java
wanpengfei-git pushed a commit that referenced this pull request Oct 24, 2023
wanpengfei-git pushed a commit that referenced this pull request Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants