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

[BugFix] fix resource name from stmt propery instead of catalog recast #34844

Merged
merged 4 commits into from
Nov 14, 2023

Conversation

dirtysalt
Copy link
Contributor

@dirtysalt dirtysalt commented Nov 13, 2023

Why I'm doing:

What I'm doing:

Fixes https://github.com/StarRocks/StarRocksTest/issues/4706


The root cause of this problem is resource name has been lower cased since 2.5

From 2.5, we add a new concept catalog. And resource name has been added to catalog name(a virtual catalog), and also lower cased. And when we fetch resource name from this catalog name, we get lower cased resource name.

// --- CatalogMgr.java
    public static class ResourceMappingCatalog {
        public static final String RESOURCE_MAPPING_CATALOG_PREFIX = "resource_mapping_inside_catalog_";

        public static boolean isResourceMappingCatalog(String catalogName) {
            return catalogName.startsWith(RESOURCE_MAPPING_CATALOG_PREFIX);
        }

        public static String getResourceMappingCatalogName(String resourceName, String type) {
           // ---- HERE, we lower case catalog name, and meanwhile we also lower case resource name
            return (RESOURCE_MAPPING_CATALOG_PREFIX + type + "_" + resourceName).toLowerCase(Locale.ROOT);
        }

        public static String toResourceName(String catalogName, String type) {
           // ----- HERE, we actually get lower cased resource name from catalog name.
            return isResourceMappingCatalog(catalogName) ?
                    catalogName.substring(RESOURCE_MAPPING_CATALOG_PREFIX.length() + type.length() + 1) : catalogName;
        }
    }

However this lower cased resource name can not be found when we downgrade FE to version 2.3. There is no catalog concept in that version, and we use ResourceMgr.java to find resource.

// ---- ResourceMgr.java
    public Resource getResource(String name) {
        this.readLock();
        try {
            return nameToResource.get(name);
        } finally {
            this.readUnlock();
        }
    }

So to fix this problem, resource name can not be fetched from catalog name, but from properties.

    public static void copyFromCatalogTable(HiveTable.Builder tableBuilder, HiveTable catalogTable,
                                            Map<String, String> properties) {
        tableBuilder
                .setCatalogName(catalogTable.getCatalogName())
                .setResourceName(properties.get(RESOURCE))  // <--- actual fix.
                .setHiveDbName(catalogTable.getDbName())
                .setHiveTableName(catalogTable.getTableName())
                .setPartitionColumnNames(catalogTable.getPartitionColumnNames())
                .setDataColumnNames(catalogTable.getDataColumnNames())
                .setTableLocation(catalogTable.getTableLocation())
                .setStorageFormat(catalogTable.getStorageFormat())
                .setCreateTime(catalogTable.getCreateTime())
                .setProperties(catalogTable.getProperties());
    }

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

Signed-off-by: yanz <dirtysalt1987@gmail.com>
@dirtysalt dirtysalt enabled auto-merge (squash) November 13, 2023 04:00
@dirtysalt dirtysalt changed the title [BugFix] fix resouce name from stmt propery instead of catalog recast [BugFix] fix resource name from stmt propery instead of catalog recast Nov 13, 2023
@dirtysalt dirtysalt disabled auto-merge November 13, 2023 04:01
@dirtysalt dirtysalt enabled auto-merge (squash) November 13, 2023 04:01
stephen-shelby
stephen-shelby previously approved these changes Nov 13, 2023
Signed-off-by: yanz <dirtysalt1987@gmail.com>
Signed-off-by: yanz <dirtysalt1987@gmail.com>
@imay
Copy link
Contributor

imay commented Nov 13, 2023

@dirtysalt could you explain more in the commit message on this CL. There is no background at all so that I can't get what you are doing in this PR.

Signed-off-by: yanz <dirtysalt1987@gmail.com>
Copy link

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 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@dirtysalt
Copy link
Contributor Author

@dirtysalt could you explain more in the commit message on this CL. There is no background at all so that I can't get what you are doing in this PR.

Sorry, I forget to clarify this root cause in CL. I've added the root cause to description.

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 30 / 34 (88.24%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/server/IcebergTableFactory.java 7 9 77.78% [76, 78]
🔵 com/starrocks/server/HudiTableFactory.java 9 11 81.82% [93, 94]
🔵 com/starrocks/server/HiveTableFactory.java 14 14 100.00% []

@dirtysalt dirtysalt merged commit d7be916 into StarRocks:main Nov 14, 2023
Copy link

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Nov 14, 2023
Copy link

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Nov 14, 2023
Copy link

@Mergifyio backport branch-3.0

@github-actions github-actions bot removed the 3.0 label Nov 14, 2023
Copy link

@Mergifyio backport branch-2.5

@github-actions github-actions bot removed the 2.5 label Nov 14, 2023
Copy link
Contributor

mergify bot commented Nov 14, 2023

backport branch-3.2

✅ Backports have been created

Copy link
Contributor

mergify bot commented Nov 14, 2023

backport branch-3.1

✅ Backports have been created

Copy link
Contributor

mergify bot commented Nov 14, 2023

backport branch-3.0

✅ Backports have been created

Copy link
Contributor

mergify bot commented Nov 14, 2023

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 14, 2023
#34844)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
(cherry picked from commit d7be916)
mergify bot pushed a commit that referenced this pull request Nov 14, 2023
#34844)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
(cherry picked from commit d7be916)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/server/HiveTableFactory.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HiveTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HudiTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/IcebergTableTest.java
mergify bot pushed a commit that referenced this pull request Nov 14, 2023
#34844)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
(cherry picked from commit d7be916)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/server/HiveTableFactory.java
#	fe/fe-core/src/main/java/com/starrocks/server/HudiTableFactory.java
#	fe/fe-core/src/main/java/com/starrocks/server/IcebergTableFactory.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HiveTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HudiTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/IcebergTableTest.java
mergify bot pushed a commit that referenced this pull request Nov 14, 2023
#34844)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
(cherry picked from commit d7be916)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/server/HiveTableFactory.java
#	fe/fe-core/src/main/java/com/starrocks/server/HudiTableFactory.java
#	fe/fe-core/src/main/java/com/starrocks/server/IcebergTableFactory.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HiveTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/HudiTableTest.java
#	fe/fe-core/src/test/java/com/starrocks/catalog/IcebergTableTest.java
wanpengfei-git pushed a commit that referenced this pull request Nov 14, 2023
#34844)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
(cherry picked from commit d7be916)
dirtysalt added a commit that referenced this pull request Nov 14, 2023
…t (backport #34844) (#34916)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
Co-authored-by: dirtysalt <dirtysalt1987@gmail.com>
andyziye pushed a commit that referenced this pull request Nov 14, 2023
…t (backport #34844) (#34915)

Signed-off-by: yanz <dirtysalt1987@gmail.com>
Co-authored-by: dirtysalt <dirtysalt1987@gmail.com>
@dirtysalt dirtysalt deleted the fix-table-resource-name branch November 15, 2023 02:10
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.

5 participants