-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-49907][ML][CONNECT] Support spark.ml on Connect #48791
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 all commits
48fdf4a
149e4bb
0d740b7
4a20866
3cff862
9ccf184
e0bbf0e
59e2f3b
4770c3f
0ba1e80
dd09f77
d40b198
d8e15f6
8775c55
2146eea
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,20 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # Spark Connect ML uses ServiceLoader to find out the supported Spark Ml estimators. | ||
| # So register the supported estimator here if you're trying to add a new one. | ||
| org.apache.spark.ml.classification.LogisticRegression |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # Spark Connect ML uses ServiceLoader to find out the supported Spark Ml non-model transformer. | ||
| # So register the supported transformer here if you're trying to add a new one. | ||
| org.apache.spark.ml.feature.VectorAssembler |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.ml.util | ||
|
|
||
| import org.apache.spark.annotation.Since | ||
|
|
||
| /** | ||
| * Trait for the Summary | ||
| * All the summaries should extend from this Summary in order to | ||
| * support connect. | ||
| */ | ||
| @Since("4.0.0") | ||
| private[spark] trait Summary | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # | ||
| # 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. | ||
| # |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're a bit in a bad position here because, high-level we should use the I'm wondering if we should do some cleanup later to delete the previous code and move this one to the right package. @WeichenXu123 what do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could also move the existing "remote" to the connect if necessary.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed that we'd better move it to the right package |
||
| # 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 typing import Optional, TYPE_CHECKING, List | ||
|
|
||
| import pyspark.sql.connect.proto as pb2 | ||
| from pyspark.sql.connect.plan import LogicalPlan | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pyspark.sql.connect.client import SparkConnectClient | ||
|
|
||
|
|
||
| class TransformerRelation(LogicalPlan): | ||
| """A logical plan for transforming of a transformer which could be a cached model | ||
| or a non-model transformer like VectorAssembler.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| child: Optional["LogicalPlan"], | ||
| name: str, | ||
| ml_params: pb2.MlParams, | ||
| uid: str = "", | ||
| is_model: bool = True, | ||
| ) -> None: | ||
| super().__init__(child) | ||
| self._name = name | ||
| self._ml_params = ml_params | ||
| self._uid = uid | ||
| self._is_model = is_model | ||
|
|
||
| def plan(self, session: "SparkConnectClient") -> pb2.Relation: | ||
| assert self._child is not None | ||
| plan = self._create_proto_relation() | ||
| plan.ml_relation.transform.input.CopyFrom(self._child.plan(session)) | ||
|
|
||
| if self._is_model: | ||
| plan.ml_relation.transform.obj_ref.CopyFrom(pb2.ObjectRef(id=self._name)) | ||
| else: | ||
| plan.ml_relation.transform.transformer.CopyFrom( | ||
| pb2.MlOperator(name=self._name, uid=self._uid, type=pb2.MlOperator.TRANSFORMER) | ||
| ) | ||
|
|
||
| if self._ml_params is not None: | ||
| plan.ml_relation.transform.params.CopyFrom(self._ml_params) | ||
|
|
||
| return plan | ||
|
|
||
|
|
||
| class AttributeRelation(LogicalPlan): | ||
| """A logical plan used in ML to represent an attribute of an instance, which | ||
| could be a model or a summary. This attribute returns a DataFrame. | ||
| """ | ||
|
|
||
| def __init__(self, ref_id: str, methods: List[pb2.Fetch.Method]) -> None: | ||
| super().__init__(None) | ||
| self._ref_id = ref_id | ||
| self._methods = methods | ||
|
|
||
| def plan(self, session: "SparkConnectClient") -> pb2.Relation: | ||
| plan = self._create_proto_relation() | ||
| plan.ml_relation.fetch.obj_ref.CopyFrom(pb2.ObjectRef(id=self._ref_id)) | ||
| plan.ml_relation.fetch.methods.extend(self._methods) | ||
| return plan | ||
Uh oh!
There was an error while loading. Please reload this page.