Class QueryGenerator
java.lang.Object
org.apache.polaris.persistence.relational.jdbc.QueryGenerator
Utility class to generate parameterized SQL queries (SELECT, INSERT, UPDATE, DELETE). Ensures
consistent SQL generation and protects against injection by managing parameters separately.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA container for the SQL string and a list of the ordered parameter values.static final recordA container for the SQL string and the ordered parameter values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic QueryGenerator.PreparedQuerygenerateDeleteQuery(@NonNull List<String> tableColumns, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Builds a DELETE query with the given conditions.static QueryGenerator.PreparedQuerygenerateDeleteQueryForEntityGrantRecords(@NonNull org.apache.polaris.core.entity.PolarisEntityCore entity, @NonNull String realmId) Builds a DELETE query to remove grant records for a given entity.static QueryGenerator.PreparedQuerygenerateExistsQuery(@NonNull List<String> tableColumns, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Generates aSELECT 1 ... WHERE ... LIMIT 1query to test row existence without fetching any column data.static QueryGenerator.PreparedQuerygenerateInsertQuery(@NonNull List<String> allColumns, @NonNull String tableName, List<Object> values, String realmId) Generates an INSERT query for a given table.static QueryGenerator.PreparedQuerygenerateOverlapQuery(String realmId, int schemaVersion, long catalogId, String baseLocation) Generate a SELECT query to find any entities that have a given realm & parent and that may overlap with a given location.static QueryGenerator.PreparedQuerygenerateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Generates a SELECT query with projection and filtering.static QueryGenerator.PreparedQuerygenerateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereClause, int limit) Generates a SELECT query bounded by a row limit.static QueryGenerator.PreparedQuerygenerateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereEquals, @NonNull Map<String, Object> whereGreater, @Nullable String orderByColumn) Generates a SELECT query with projection and filtering.static QueryGenerator.PreparedQuerygenerateSelectQueryWithEntityIds(@NonNull String realmId, int schemaVersion, @NonNull List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) Builds a SELECT query using a list of entity ID pairs (catalog_id, id).static QueryGenerator.PreparedQuerygenerateSelectQueryWithEntityIdsVersionOnly(@NonNull String realmId, @NonNull List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) LikegenerateSelectQueryWithEntityIds(String, int, List)but selects onlyModelEntity.VERSION_COLUMNS.static QueryGenerator.PreparedQuerygenerateUpdateQuery(@NonNull List<String> allColumns, @NonNull String tableName, @NonNull List<Object> values, @NonNull Map<String, Object> whereClause) Builds an UPDATE query.
-
Constructor Details
-
QueryGenerator
public QueryGenerator()
-
-
Method Details
-
generateSelectQuery
public static QueryGenerator.PreparedQuery generateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Generates a SELECT query with projection and filtering.- Parameters:
projections- List of columns to retrieve.tableName- Target table name.whereClause- Column-value pairs used in WHERE filtering.- Returns:
- A parameterized SELECT query.
- Throws:
IllegalArgumentException- if any whereClause column isn't in projections or if limit is not positive.
-
generateSelectQuery
public static QueryGenerator.PreparedQuery generateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereClause, int limit) Generates a SELECT query bounded by a row limit. Useful for existence checks that only need to know whether any matching row exists, avoiding fetching and materializing the full result set.- Parameters:
projections- List of columns to retrieve.tableName- Target table name.whereClause- Column-value pairs used in WHERE filtering.limit- Maximum number of rows to return.- Returns:
- A parameterized SELECT query with a LIMIT clause.
- Throws:
IllegalArgumentException- if any whereClause column isn't in projections.
-
generateSelectQuery
public static QueryGenerator.PreparedQuery generateSelectQuery(@NonNull List<String> projections, @NonNull String tableName, @NonNull Map<String, Object> whereEquals, @NonNull Map<String, Object> whereGreater, @Nullable String orderByColumn) Generates a SELECT query with projection and filtering.- Parameters:
projections- List of columns to retrieve.tableName- Target table name.whereEquals- Column-value pairs used in WHERE filtering.- Returns:
- A parameterized SELECT query.
- Throws:
IllegalArgumentException- if any whereClause column isn't in projections.
-
generateDeleteQueryForEntityGrantRecords
public static QueryGenerator.PreparedQuery generateDeleteQueryForEntityGrantRecords(@NonNull org.apache.polaris.core.entity.PolarisEntityCore entity, @NonNull String realmId) Builds a DELETE query to remove grant records for a given entity.- Parameters:
entity- The target entity (either grantee or securable).realmId- The associated realm.- Returns:
- A DELETE query removing all grants for this entity.
-
generateSelectQueryWithEntityIds
public static QueryGenerator.PreparedQuery generateSelectQueryWithEntityIds(@NonNull String realmId, int schemaVersion, @NonNull List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) Builds a SELECT query using a list of entity ID pairs (catalog_id, id).- Parameters:
realmId- Realm to filter by.schemaVersion- The schema version of entities table to queryentityIds- List of PolarisEntityId pairs.- Returns:
- SELECT query to retrieve matching entities.
- Throws:
IllegalArgumentException- if entityIds is empty.
-
generateSelectQueryWithEntityIdsVersionOnly
public static QueryGenerator.PreparedQuery generateSelectQueryWithEntityIdsVersionOnly(@NonNull String realmId, @NonNull List<org.apache.polaris.core.entity.PolarisEntityId> entityIds) LikegenerateSelectQueryWithEntityIds(String, int, List)but selects onlyModelEntity.VERSION_COLUMNS. Used bylookupEntityVersionsto avoid fetching large JSON property blobs on the cache-validation hot path. -
generateInsertQuery
public static QueryGenerator.PreparedQuery generateInsertQuery(@NonNull List<String> allColumns, @NonNull String tableName, List<Object> values, String realmId) Generates an INSERT query for a given table.- Parameters:
allColumns- Columns to insert values into.tableName- Target table name.values- Values for each column (must match order of columns).realmId- Realm value to append.- Returns:
- INSERT query with value bindings.
-
generateUpdateQuery
public static QueryGenerator.PreparedQuery generateUpdateQuery(@NonNull List<String> allColumns, @NonNull String tableName, @NonNull List<Object> values, @NonNull Map<String, Object> whereClause) Builds an UPDATE query.- Parameters:
allColumns- Columns to update.tableName- Target table.values- New values (must match columns in order).whereClause- Conditions for filtering rows to update.- Returns:
- UPDATE query with parameter values.
-
generateDeleteQuery
public static QueryGenerator.PreparedQuery generateDeleteQuery(@NonNull List<String> tableColumns, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Builds a DELETE query with the given conditions.- Parameters:
tableColumns- List of valid table columns.tableName- Target table.whereClause- Column-value filters.- Returns:
- DELETE query with parameter bindings.
-
generateExistsQuery
public static QueryGenerator.PreparedQuery generateExistsQuery(@NonNull List<String> tableColumns, @NonNull String tableName, @NonNull Map<String, Object> whereClause) Generates aSELECT 1 ... WHERE ... LIMIT 1query to test row existence without fetching any column data. All filter conditions must be supplied inwhereClause. -
generateOverlapQuery
public static QueryGenerator.PreparedQuery generateOverlapQuery(String realmId, int schemaVersion, long catalogId, String baseLocation) Generate a SELECT query to find any entities that have a given realm & parent and that may overlap with a given location. The check is performed without consideration for the scheme, so a path on one storage type may give a false positive for overlapping with another storage type. This should be combined with a check using `StorageLocation`.- Parameters:
realmId- A realm to search withinschemaVersion- The schema version of entities table to querycatalogId- A catalog entity to search withinbaseLocation- The base location to look for overlap with, with or without a scheme- Returns:
- The list of possibly overlapping entities that meet the criteria
-