@@ -56,8 +56,11 @@ class PythonTableProvider(shortName: String) extends TableProvider {
5656 schema : StructType ,
5757 partitioning : Array [Transform ],
5858 properties : java.util.Map [String , String ]): Table = {
59+ assert(partitioning.isEmpty)
5960 new PythonTable (shortName, source, schema)
6061 }
62+
63+ override def supportsExternalMetadata (): Boolean = true
6164}
6265
6366class PythonTable (shortName : String , source : UserDefinedPythonDataSource , givenSchema : StructType )
@@ -70,8 +73,8 @@ class PythonTable(shortName: String, source: UserDefinedPythonDataSource, givenS
7073 override def newScanBuilder (options : CaseInsensitiveStringMap ): ScanBuilder = {
7174 new ScanBuilder with Batch with Scan {
7275
73- private lazy val pythonFunc : PythonFunction = source.createPythonFunction(
74- shortName, options, Some ( givenSchema) )
76+ private lazy val pythonFunc : PythonFunction =
77+ source.createPythonFunction( shortName, options, givenSchema)
7578
7679 private lazy val info : PythonDataSourceReadInfo =
7780 new UserDefinedPythonDataSourceReadRunner (
@@ -163,37 +166,32 @@ class PythonPartitionReaderFactory(
163166 */
164167case class UserDefinedPythonDataSource (dataSourceCls : PythonFunction ) {
165168
166- private var pythonResult : PythonDataSourceCreationResult = _
167-
168- private def getOrCreatePythonResult (
169+ private def createPythonResult (
169170 shortName : String ,
170171 options : CaseInsensitiveStringMap ,
171172 userSpecifiedSchema : Option [StructType ]): PythonDataSourceCreationResult = {
172- if (pythonResult != null ) return pythonResult
173- val runner = new UserDefinedPythonDataSourceRunner (
173+ new UserDefinedPythonDataSourceRunner (
174174 dataSourceCls,
175175 shortName,
176176 userSpecifiedSchema,
177- CaseInsensitiveMap (options.asCaseSensitiveMap().asScala.toMap))
178- pythonResult = runner.runInPython()
179- pythonResult
177+ CaseInsensitiveMap (options.asCaseSensitiveMap().asScala.toMap)).runInPython()
180178 }
181179
182180 def inferSchema (
183181 shortName : String ,
184182 options : CaseInsensitiveStringMap ): StructType = {
185- getOrCreatePythonResult (shortName, options, None ).schema
183+ createPythonResult (shortName, options, None ).schema
186184 }
187185
188186 def createPythonFunction (
189187 shortName : String ,
190188 options : CaseInsensitiveStringMap ,
191- userSpecifiedSchema : Option [ StructType ] ): PythonFunction = {
192- val pickledDataSourceInstance = getOrCreatePythonResult (
193- shortName, options, userSpecifiedSchema ).dataSource
189+ givenSchema : StructType ): PythonFunction = {
190+ val dataSource = createPythonResult (
191+ shortName, options, Some (givenSchema) ).dataSource
194192
195193 SimplePythonFunction (
196- command = pickledDataSourceInstance .toImmutableArraySeq,
194+ command = dataSource .toImmutableArraySeq,
197195 envVars = dataSourceCls.envVars,
198196 pythonIncludes = dataSourceCls.pythonIncludes,
199197 pythonExec = dataSourceCls.pythonExec,
0 commit comments