-
Notifications
You must be signed in to change notification settings - Fork 80
Refactor(spark-3.5): Make OpenHouse SQL extensions standalone #660
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
Draft
mkuchenbecker
wants to merge
2
commits into
main
Choose a base branch
from
mkuchenb/spark35-sql-standalone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 244 additions & 0 deletions
244
...tlr/com/linkedin/openhouse/spark/sql/catalyst/parser/extensions/OpenhouseSqlExtensions.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| grammar OpenhouseSqlExtensions; | ||
|
|
||
| @lexer::members { | ||
| /** | ||
| * This method will be called when we see '/*' and try to match it as a bracketed comment. | ||
| * If the next character is '+', it should be parsed as hint later, and we cannot match | ||
| * it as a bracketed comment. | ||
| * | ||
| * Returns true if the next character is '+'. | ||
| */ | ||
| public boolean isHint() { | ||
| int nextChar = _input.LA(1); | ||
| if (nextChar == '+') { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| singleStatement | ||
| : statement EOF | ||
| ; | ||
|
|
||
| statement | ||
| : ALTER TABLE multipartIdentifier SET POLICY '(' retentionPolicy (columnRetentionPolicy)? ')' #setRetentionPolicy | ||
| | ALTER TABLE multipartIdentifier SET POLICY '(' replicationPolicy ')' #setReplicationPolicy | ||
| | ALTER TABLE multipartIdentifier UNSET POLICY '(' replication ')' #unSetReplicationPolicy | ||
| | ALTER TABLE multipartIdentifier SET POLICY '(' sharingPolicy ')' #setSharingPolicy | ||
| | ALTER TABLE multipartIdentifier SET POLICY '(' historyPolicy ')' #setHistoryPolicy | ||
| | ALTER TABLE multipartIdentifier MODIFY columnNameClause SET columnPolicy #setColumnPolicyTag | ||
| | GRANT privilege ON grantableResource TO principal #grantStatement | ||
| | REVOKE privilege ON grantableResource FROM principal #revokeStatement | ||
| | SHOW GRANTS ON grantableResource #showGrantsStatement | ||
| ; | ||
|
|
||
| multipartIdentifier | ||
| : parts+=identifier ('.' parts+=identifier)* | ||
| ; | ||
|
|
||
| privilege | ||
| : columnLevelPrivilege | ||
| | SELECT | DESCRIBE | ALTER | GRANT_REVOKE | CREATE_TABLE | ||
| ; | ||
|
|
||
| columnLevelPrivilege | ||
| : SELECT policyTag | ||
| ; | ||
|
|
||
| grantableResource | ||
| : TABLE multipartIdentifier | ||
| | DATABASE multipartIdentifier | ||
| ; | ||
|
|
||
| principal | ||
| : identifier | ||
| ; | ||
|
|
||
| identifier | ||
| : IDENTIFIER | ||
| | quotedIdentifier | ||
| | nonReserved | ||
| ; | ||
|
|
||
| quotedIdentifier | ||
| : BACKQUOTED_IDENTIFIER | ||
| ; | ||
|
|
||
| nonReserved | ||
| : ALTER | TABLE | SET | POLICY | RETENTION | SHARING | REPLICATION | HISTORY | ||
| | GRANT | REVOKE | ON | TO | SHOW | GRANTS | PATTERN | WHERE | COLUMN | ||
| ; | ||
|
|
||
| sharingPolicy | ||
| : SHARING '=' BOOLEAN | ||
| ; | ||
|
|
||
| BOOLEAN | ||
| : 'TRUE' | 'FALSE' | ||
| ; | ||
|
|
||
| retentionPolicy | ||
| : RETENTION '=' duration | ||
| ; | ||
|
|
||
| columnRetentionPolicy | ||
| : ON columnNameClause (columnRetentionPolicyPatternClause)? | ||
| ; | ||
|
|
||
| replication | ||
| : REPLICATION | ||
| ; | ||
|
|
||
| replicationPolicy | ||
| : replication '=' tableReplicationPolicy | ||
| ; | ||
|
|
||
| tableReplicationPolicy | ||
| : '(' replicationPolicyClause (',' replicationPolicyClause)* ')' | ||
| ; | ||
|
|
||
| replicationPolicyClause | ||
| : '{' replicationPolicyClusterClause (',' replicationPolicyIntervalClause)? '}' | ||
| ; | ||
|
|
||
| replicationPolicyClusterClause | ||
| : DESTINATION ':' STRING | ||
| ; | ||
|
|
||
| replicationPolicyIntervalClause | ||
| : INTERVAL ':' RETENTION_HOUR | ||
| | INTERVAL ':' RETENTION_DAY | ||
| ; | ||
|
|
||
| columnRetentionPolicyPatternClause | ||
| : WHERE retentionColumnPatternClause | ||
| ; | ||
|
|
||
| columnNameClause | ||
| : COLUMN identifier | ||
| ; | ||
|
|
||
| retentionColumnPatternClause | ||
| : PATTERN '=' STRING | ||
| ; | ||
|
|
||
| duration | ||
| : RETENTION_DAY | ||
| | RETENTION_YEAR | ||
| | RETENTION_MONTH | ||
| | RETENTION_HOUR | ||
| ; | ||
|
|
||
| RETENTION_DAY | ||
| : POSITIVE_INTEGER 'D' | ||
| ; | ||
|
|
||
| RETENTION_YEAR | ||
| : POSITIVE_INTEGER 'Y' | ||
| ; | ||
|
|
||
| RETENTION_MONTH | ||
| : POSITIVE_INTEGER 'M' | ||
| ; | ||
|
|
||
| RETENTION_HOUR | ||
| : POSITIVE_INTEGER 'H' | ||
| ; | ||
|
|
||
| columnPolicy | ||
| : TAG '=' multiTagIdentifier | ||
| | TAG '=' '(' NONE ')' | ||
| ; | ||
|
|
||
| multiTagIdentifier | ||
| : '(' policyTag (',' policyTag)* ')' | ||
| ; | ||
|
|
||
| policyTag | ||
| : PII | HC | ||
| ; | ||
|
|
||
| historyPolicy | ||
| : HISTORY maxAge? versions? | ||
| ; | ||
|
|
||
| maxAge | ||
| : MAX_AGE'='duration | ||
| ; | ||
|
|
||
| versions | ||
| : VERSIONS'='POSITIVE_INTEGER | ||
| ; | ||
|
|
||
| ALTER: 'ALTER'; | ||
| TABLE: 'TABLE'; | ||
| SET: 'SET'; | ||
| UNSET: 'UNSET'; | ||
| POLICY: 'POLICY'; | ||
| RETENTION: 'RETENTION'; | ||
| REPLICATION: 'REPLICATION'; | ||
| HISTORY: 'HISTORY'; | ||
| SHARING: 'SHARING'; | ||
| GRANT: 'GRANT'; | ||
| REVOKE: 'REVOKE'; | ||
| ON: 'ON'; | ||
| TO: 'TO'; | ||
| FROM: 'FROM'; | ||
| SELECT: 'SELECT'; | ||
| DESCRIBE: 'DESCRIBE'; | ||
| GRANT_REVOKE: 'MANAGE GRANTS'; | ||
| CREATE_TABLE: 'CREATE TABLE'; | ||
| DATABASE: 'DATABASE'; | ||
| SHOW: 'SHOW'; | ||
| GRANTS: 'GRANTS'; | ||
| PATTERN: 'PATTERN'; | ||
| DESTINATION: 'DESTINATION'; | ||
| INTERVAL: 'INTERVAL'; | ||
| WHERE: 'WHERE'; | ||
| COLUMN: 'COLUMN'; | ||
| PII: 'PII'; | ||
| HC: 'HC'; | ||
| MODIFY: 'MODIFY'; | ||
| TAG: 'TAG'; | ||
| NONE: 'NONE'; | ||
| VERSIONS: 'VERSIONS'; | ||
| MAX_AGE: 'MAX_AGE'; | ||
|
|
||
| POSITIVE_INTEGER | ||
| : DIGIT+ | ||
| ; | ||
|
|
||
| STRING | ||
| : '\'' ( ~('\''|'\\') | ('\\' .) )* '\'' | ||
| | '"' ( ~('"'|'\\') | ('\\' .) )* '"' | ||
| ; | ||
|
|
||
| IDENTIFIER | ||
| : (LETTER | DIGIT | '_')+ | ||
| ; | ||
|
|
||
| BACKQUOTED_IDENTIFIER | ||
| : '`' ( ~'`' | '``' )* '`' | ||
| ; | ||
|
|
||
| fragment DIGIT | ||
| : [0-9] | ||
| ; | ||
|
|
||
| fragment LETTER | ||
| : [A-Z] | ||
| ; | ||
|
|
||
| SIMPLE_COMMENT | ||
| : '--' ('\\\n' | ~[\r\n])* '\r'? '\n'? -> channel(HIDDEN) | ||
| ; | ||
|
|
||
| BRACKETED_COMMENT | ||
| : '/*' {!isHint()}? (BRACKETED_COMMENT|.)*? '*/' -> channel(HIDDEN) | ||
| ; | ||
|
|
||
| WS | ||
| : [ \r\n\t]+ -> channel(HIDDEN) | ||
| ; |
18 changes: 18 additions & 0 deletions
18
.../openhouse-spark-runtime/src/main/java/com/linkedin/openhouse/spark/OpenHouseCatalog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.linkedin.openhouse.spark; | ||
|
|
||
| /** | ||
| * Catalog implementation to create, read, update and delete tables in OpenHouse. This class | ||
| * leverages Openhouse tableclient to perform CRUD operations on Tables resource in the Catalog | ||
| * service. This implementation provides client side catalog implementation for Iceberg tables in | ||
| * Spark. | ||
| * | ||
| * <p>Catalog can be instantiated as a Iceberg catalog, with following configurations: | ||
| * spark.sql.catalog.openhouse=org.apache.iceberg.spark.SparkCatalog | ||
| * spark.sql.catalog.openhouse.catalog-impl=com.linkedin.openhouse.spark.OpenHouseCatalog | ||
| * spark.sql.catalog.openhouse.metrics-reporter-impl=com.linkedin.openhouse.javaclient.OpenHouseMetricsReporter | ||
| * spark.sql.catalog.openhouse.uri=http://[openhouse service host]:[openhouse service port] | ||
| * spark.sql.catalog.openhouse.cluster=[openhouse cluster name] | ||
| * | ||
| * <p>It can be used in spark shell as follows: spark.sql("USE openhouse") | ||
| */ | ||
| public class OpenHouseCatalog extends com.linkedin.openhouse.javaclient.OpenHouseCatalog {} |
12 changes: 12 additions & 0 deletions
12
.../main/scala/com/linkedin/openhouse/spark/extensions/OpenhouseSparkSessionExtensions.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.linkedin.openhouse.spark.extensions | ||
|
|
||
| import com.linkedin.openhouse.spark.sql.catalyst.parser.extensions.OpenhouseSparkSqlExtensionsParser | ||
| import com.linkedin.openhouse.spark.sql.execution.datasources.v2.OpenhouseDataSourceV2Strategy | ||
| import org.apache.spark.sql.SparkSessionExtensions | ||
|
|
||
| class OpenhouseSparkSessionExtensions extends (SparkSessionExtensions => Unit) { | ||
| override def apply(extensions: SparkSessionExtensions): Unit = { | ||
| extensions.injectParser { case (_, parser) => new OpenhouseSparkSqlExtensionsParser(parser) } | ||
| extensions.injectPlannerStrategy( spark => OpenhouseDataSourceV2Strategy(spark)) | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...untime/src/main/scala/com/linkedin/openhouse/spark/sql/catalyst/constants/Principal.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.linkedin.openhouse.spark.sql.catalyst.constants | ||
|
|
||
| /** | ||
| * This object is used to represent keyword global user group "PUBLIC" which maps to the acl policy representation "*" | ||
| */ | ||
| object Principal { | ||
| private val GLOBAL_USER_GROUP = "PUBLIC" | ||
| private val GLOBAL_USER_GROUP_ACL = "*" | ||
| def apply(principal: String): String = principal toUpperCase() match { | ||
| case GLOBAL_USER_GROUP => GLOBAL_USER_GROUP_ACL | ||
| case _ => principal | ||
| } | ||
|
|
||
| def unapply(principalAcl: String): Option[String] = principalAcl match { | ||
| case GLOBAL_USER_GROUP_ACL => Some(GLOBAL_USER_GROUP) | ||
| case _ => Some(principalAcl) | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...c/main/scala/com/linkedin/openhouse/spark/sql/catalyst/enums/GrantableResourceTypes.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.linkedin.openhouse.spark.sql.catalyst.enums | ||
|
|
||
| private[sql] object GrantableResourceTypes extends Enumeration { | ||
| type GrantableResourceType = Value | ||
| val TABLE, DATABASE = Value | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is directly compiling rather than using the 3.1 generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes — that's intentional. The Spark 3.5 module now owns and runs ANTLR over its own
src/main/antlr/.../OpenhouseSqlExtensions.g4, withsourceSets.main.java.srcDirspointing at its ownbuild/generated-src/antlr/mainandcompileJava.dependsOn runAntlr. Reusing the Spark 3.1 generated sources would keep Spark 3.5 coupled to the 3.1 module's build output/task ordering and would prevent the 3.5 grammar from diverging for 3.5-specific SQL extensions. This keeps the runtime self-contained while preserving the same generated parser package/shape.