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

[UT] optimize error message when creating hive/iceberg db/table #45612

Merged
merged 1 commit into from
May 15, 2024

Conversation

stephen-shelby
Copy link
Contributor

@stephen-shelby stephen-shelby commented May 14, 2024

Why I'm doing:

What I'm doing:

  1. support create hive database on glue without location
  2. support create hive table on glue with location
  3. optimize error message.

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
  • This is a backport pr

Bugfix cherry-pick branch check:

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

@stephen-shelby stephen-shelby requested a review from a team as a code owner May 14, 2024 12:54
throw new StarRocksConnectorException("Failed checking path: " + path);
}
}

public static void createDirectory(Path path, Configuration conf) {
try {
FileSystem fileSystem = FileSystem.get(path.toUri(), conf);
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
the removal of the check for LOCATION_PROPERTY in the checkLocationProperties method.

You can modify the code like this:

public static void checkLocationProperties(Map<String, String> properties) throws DdlException {
    // Add back the check for both EXTERNAL_LOCATION_PROPERTY and LOCATION_PROPERTY
    if (properties.containsKey(EXTERNAL_LOCATION_PROPERTY) || properties.containsKey(LOCATION_PROPERTY)) {
        throw new DdlException("Can't create non-managed Hive table. " +
                "Only supports creating hive table under Database location. " +
                "You could execute command without location properties");
    }
}

This modification considers scenarios where either EXTERNAL_LOCATION_PROPERTY or the previously checked LOCATION_PROPERTY are included in the properties map, ensuring that the code handles both situations appropriately and prevents the creation of non-managed Hive tables with inappropriate location properties.

throw new StarRocksConnectorException("Failed to find location in database '%s'. Please define the location" +
" when you create table or recreate another database with location." +
" You could execute the SQL command like 'CREATE TABLE <table_name> <columns> " +
"PROPERTIES('location' = '<location>')", dbName);
}

String dbLocation = database.getLocation();
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Database location validation is removed for GLUE metastore.

You can modify the code like this:

@@ -104,12 +103,6 @@ public void createDb(String dbName, Map<String, String> properties) {
             }
         }
 
+        if ((dbLocation == null || dbLocation.isEmpty()) && metastoreType == MetastoreType.GLUE) {
+            throw new StarRocksConnectorException("The database location must be set when using glue. " +
+                    "you could execute command like " +
+                    "'CREATE DATABASE <db_name> properties('location'='s3://<bucket>/<your_db_path>')'");
+        }
+
         metastore.createDb(dbName, properties);
     }

Reintroducing the check for a database location ensures that when using the GLUE metastore, the database location must be explicitly defined. This is important because the absence of this validation might lead to an inconsistency in the way databases are created between different metastores and potentially cause runtime failures or misconfigurations when relying on GLUE’s behavior.

"PROPERTIES('location' = '<location>')", dbName);
}
}

Table nativeTable = delegate.buildTable(TableIdentifier.of(dbName, tableName), schema)
.withLocation(location)
.withPartitionSpec(partitionSpec)
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
location variable not updated with dbLocation after fetching it when location is null or empty

You can modify the code like this:

if (Strings.isNullOrEmpty(location)) {
    String dbLocation = getDB(dbName).getLocation();
    if (Strings.isNullOrEmpty(dbLocation)) {
        throw new StarRocksConnectorException("Failed to find location in database '%s'. Please define the location" +
                 " when you create table or recreate another database with location." +
                 " You could execute the SQL command like 'CREATE TABLE <table_name> <columns> " +
                 "PROPERTIES('location' = '<location>')", dbName);
    }
    location = dbLocation; // Update location with dbLocation
}

@stephen-shelby stephen-shelby changed the title [Enhancement] optimize error message when creating hive/iceberg db/table [UT] optimize error message when creating hive/iceberg db/table May 14, 2024
Copy link

sonarcloud bot commented May 14, 2024

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 7 / 30 (23.33%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/connector/iceberg/glue/IcebergGlueCatalog.java 0 4 00.00% [157, 158, 159, 160]
🔵 com/starrocks/connector/hive/glue/metastore/GlueMetastoreClientDelegate.java 0 6 00.00% [164, 165, 166, 168, 169, 176]
🔵 com/starrocks/connector/hive/HiveWriteUtils.java 1 6 16.67% [72, 73, 74, 75, 76]
🔵 com/starrocks/connector/hive/HiveMetastoreOperations.java 6 14 42.86% [154, 155, 156, 157, 158, 159, 163, 209]

@andyziye andyziye merged commit 157a37a into StarRocks:main May 15, 2024
48 of 49 checks passed
Copy link

@Mergifyio backport branch-3.3

Copy link

@Mergifyio backport branch-3.2

Copy link
Contributor

mergify bot commented May 15, 2024

backport branch-3.3

✅ Backports have been created

Copy link
Contributor

mergify bot commented May 15, 2024

backport branch-3.2

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 15, 2024
Signed-off-by: stephen <stephen5217@163.com>
(cherry picked from commit 157a37a)
mergify bot pushed a commit that referenced this pull request May 15, 2024
Signed-off-by: stephen <stephen5217@163.com>
(cherry picked from commit 157a37a)
wanpengfei-git pushed a commit that referenced this pull request May 15, 2024
…port #45612) (#45628)

Co-authored-by: stephen <91597003+stephen-shelby@users.noreply.github.com>
wanpengfei-git pushed a commit that referenced this pull request May 15, 2024
…port #45612) (#45627)

Co-authored-by: stephen <91597003+stephen-shelby@users.noreply.github.com>
@stephen-shelby stephen-shelby deleted the optimize_create_table_log branch May 16, 2024 01:45
node pushed a commit to vivo/starrocks that referenced this pull request May 17, 2024
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.

None yet

4 participants