-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-52853][SDP] Prevent imperative PySpark methods in declarative pipelines #51590
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
Changes from 11 commits
66878c1
52c7b3b
cfbf024
da51940
ec7f88c
a7a957d
422dba8
4ae627e
39a1eea
e90dbce
dba000b
f5292aa
43f607f
d0e7b5d
8180841
18eecde
452402c
9b7f5b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,141 @@ | ||||||
| # | ||||||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||||||
| # contributor license agreements. See the NOTICE file distributed with | ||||||
| # this work for additional information regarding copyright ownership. | ||||||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||||||
| # (the "License"); you may not use this file except in compliance with | ||||||
| # the License. You may obtain a copy of the License at | ||||||
| # | ||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| # | ||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| # See the License for the specific language governing permissions and | ||||||
| # limitations under the License. | ||||||
| # | ||||||
| from contextlib import contextmanager | ||||||
| from typing import Generator, NoReturn, List, Callable | ||||||
|
|
||||||
| from pyspark.errors import PySparkException | ||||||
| from pyspark.sql.connect.catalog import Catalog | ||||||
| from pyspark.sql.connect.conf import RuntimeConf | ||||||
| from pyspark.sql.connect.dataframe import DataFrame | ||||||
| from pyspark.sql.connect.udf import UDFRegistration | ||||||
|
|
||||||
| # pyspark methods that should be blocked from executing in python pipeline definition files | ||||||
| BLOCKED_METHODS: List = [ | ||||||
| { | ||||||
| "class": RuntimeConf, | ||||||
| "method": "set", | ||||||
| "suggestion": "Instead set configuration via the pipeline spec " | ||||||
|
||||||
| "or use the 'spark_conf' argument in various decorators", | ||||||
| }, | ||||||
| { | ||||||
| "class": Catalog, | ||||||
| "method": "setCurrentCatalog", | ||||||
| "suggestion": "Instead set catalog via the pipeline spec " | ||||||
| "or the 'name' argument on the dataset decorators", | ||||||
| }, | ||||||
| { | ||||||
| "class": Catalog, | ||||||
| "method": "setCurrentDatabase", | ||||||
| "suggestion": "Instead set database via the pipeline spec " | ||||||
| "or the 'name' argument on the dataset decorators", | ||||||
| }, | ||||||
| { | ||||||
| "class": Catalog, | ||||||
| "method": "dropTempView", | ||||||
| "suggestion": "Instead remove the temporary view definition directly", | ||||||
| }, | ||||||
| { | ||||||
| "class": Catalog, | ||||||
| "method": "dropGlobalTempView", | ||||||
| "suggestion": "Instead remove the temporary view definition directly", | ||||||
| }, | ||||||
| { | ||||||
| "class": DataFrame, | ||||||
| "method": "createTempView", | ||||||
| "suggestion": "Instead use the @temporary_view decorator to define temporary views", | ||||||
| }, | ||||||
| { | ||||||
| "class": DataFrame, | ||||||
| "method": "createOrReplaceTempView", | ||||||
| "suggestion": "Instead use the @temporary_view decorator to define temporary views", | ||||||
| }, | ||||||
| { | ||||||
| "class": DataFrame, | ||||||
| "method": "createGlobalTempView", | ||||||
| "suggestion": "Instead use the @temporary_view decorator to define temporary views", | ||||||
| }, | ||||||
| { | ||||||
| "class": DataFrame, | ||||||
| "method": "createOrReplaceGlobalTempView", | ||||||
| "suggestion": "Instead use the @temporary_view decorator to define temporary views", | ||||||
| }, | ||||||
| { | ||||||
| "class": UDFRegistration, | ||||||
| "method": "register", | ||||||
| "suggestion": "", | ||||||
| }, | ||||||
| { | ||||||
| "class": UDFRegistration, | ||||||
| "method": "registerJavaFunction", | ||||||
| "suggestion": "", | ||||||
| }, | ||||||
| { | ||||||
| "class": UDFRegistration, | ||||||
| "method": "registerJavaUDAF", | ||||||
| "suggestion": "", | ||||||
| }, | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| def _create_blocked_method(error_method_name: str, suggestion: str) -> Callable: | ||||||
| def blocked_method(*args: object, **kwargs: object) -> NoReturn: | ||||||
| raise PySparkException( | ||||||
| errorClass="IMPERATIVE_CONSTRUCT_IN_DECLARATIVE_PIPELINE", | ||||||
| messageParameters={ | ||||||
| "method": error_method_name, | ||||||
| "suggestion": suggestion, | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| return blocked_method | ||||||
|
|
||||||
|
|
||||||
| @contextmanager | ||||||
| def block_imperative_construct() -> Generator[None, None, None]: | ||||||
|
||||||
| def block_imperative_construct() -> Generator[None, None, None]: | |
| def block_imperative_constructs() -> Generator[None, None, None]: |
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.
renamed to block_session_mutations to be more clear
Uh oh!
There was an error while loading. Please reload this page.