HyukjinKwon commented on code in PR #44504: URL: https://github.com/apache/spark/pull/44504#discussion_r1437301627
########## python/pyspark/sql/worker/lookup_data_sources.py: ########## @@ -0,0 +1,99 @@ +# +# 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 importlib import import_module +from pkgutil import iter_modules +import os +import sys +from typing import IO + +from pyspark.accumulators import _accumulatorRegistry +from pyspark.java_gateway import local_connect_and_auth +from pyspark.serializers import ( + read_int, + write_int, + write_with_length, + SpecialLengths, +) +from pyspark.sql.datasource import DataSource +from pyspark.util import handle_worker_exception +from pyspark.worker_util import ( + check_python_version, + pickleSer, + send_accumulator_updates, + setup_broadcasts, + setup_memory_limits, + setup_spark_files, +) + + +def main(infile: IO, outfile: IO) -> None: + """ + Main method for looking up the available Python Data Sources in Python path. + + This process is invoked from the `UserDefinedPythonDataSourceLookupRunner.runInPython` + method in `UserDefinedPythonDataSource.lookupAllDataSourcesInPython` when the first + call related to Python Data Source happens via `DataSourceManager`. + + This is responsible for searching the available Python Data Sources so they can be + statically registered automatically. + """ + try: + check_python_version(infile) + + memory_limit_mb = int(os.environ.get("PYSPARK_PLANNER_MEMORY_MB", "-1")) + setup_memory_limits(memory_limit_mb) + + setup_spark_files(infile) + setup_broadcasts(infile) + + _accumulatorRegistry.clear() + + infos = {} + for info in iter_modules(): + if info.name.startswith("pyspark_"): + mod = import_module(info.name) + if hasattr(mod, "DefaultSource") and isinstance(mod.DefaultSource, DataSource): Review Comment: argh -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
