singhpk234 commented on code in PR #1686: URL: https://github.com/apache/polaris/pull/1686#discussion_r2150874187
########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/QueryGenerator.java: ########## @@ -190,6 +212,35 @@ public static String generateWhereClause(@Nonnull Map<String, Object> whereClaus return !whereConditionsString.isEmpty() ? (" WHERE " + whereConditionsString) : ""; } + @VisibleForTesting + public static String generateVersionQuery() { + return "SELECT version_value FROM POLARIS_SCHEMA.VERSION"; + } + + @VisibleForTesting + public static <T extends PolarisEntity & LocationBasedEntity> String generateOverlapQuery( + String realmId, T entity) { + String location = entity.getBaseLocation(); + String[] components = location.split("/"); + ArrayList<String> locationClauseComponents = new ArrayList<>(); + StringBuilder pathBuilder = new StringBuilder(); + for (String component : components) { + pathBuilder.append(component).append("/"); + locationClauseComponents.add(String.format("location = '%s'", pathBuilder)); + } + locationClauseComponents.add(String.format("location LIKE '%s%%'", location)); Review Comment: This is prefix search, wondering if we normalize as of today path starting via S3 and S3A differently ? we can skip these controversy by skipping the '://<path>' removing the prefix of scheme WDYT ? ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java: ########## @@ -556,6 +565,55 @@ public boolean hasChildren( } } + private int loadVersion() { + String query = generateVersionQuery(); + try { + List<SchemaVersion> schemaVersion = + datasourceOperations.executeSelect(query, new SchemaVersion()); + if (schemaVersion == null || schemaVersion.size() != 1) { + throw new RuntimeException("Failed to retrieve schema version"); + } + return schemaVersion.getFirst().getValue(); + } catch (SQLException e) { + LOGGER.error("Failed to load schema version due to {}", e.getMessage(), e); + throw new RuntimeException("Failed to retrieve schema version", e); + } + } + + /** {@inheritDoc} */ + @Override + public <T extends PolarisEntity & LocationBasedEntity> + Optional<Optional<String>> hasOverlappingSiblings( + @Nonnull PolarisCallContext callContext, T entity) { + if (this.version < 2) { + return Optional.empty(); + } + if (entity.getBaseLocation().chars().filter(ch -> ch == '/').count() + > MAX_LOCATION_COMPONENTS) { + return Optional.empty(); + } + + String query = QueryGenerator.generateOverlapQuery(realmId, entity); Review Comment: lets use PreparedQuery ? ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/QueryGenerator.java: ########## @@ -190,6 +212,35 @@ public static String generateWhereClause(@Nonnull Map<String, Object> whereClaus return !whereConditionsString.isEmpty() ? (" WHERE " + whereConditionsString) : ""; } + @VisibleForTesting + public static String generateVersionQuery() { + return "SELECT version_value FROM POLARIS_SCHEMA.VERSION"; + } + + @VisibleForTesting + public static <T extends PolarisEntity & LocationBasedEntity> String generateOverlapQuery( Review Comment: is package scope not sufficient ? ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java: ########## @@ -121,7 +121,7 @@ private DatasourceOperations getDatasourceOperations(boolean isBootstrap) { try { DatabaseType databaseType = getDatabaseType(); databaseOperations.executeScript( - String.format("%s/schema-v1.sql", databaseType.getDisplayName())); + String.format("%s/schema-v2.sql", databaseType.getDisplayName())); Review Comment: is there a way we can configure the version from the version of datasource ops ? also wondering what is we want to different version different databaseType ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org