HyukjinKwon commented on a change in pull request #33570:
URL: https://github.com/apache/spark/pull/33570#discussion_r678858960
##########
File path: python/pyspark/pandas/internal.py
##########
@@ -917,124 +905,21 @@ def attach_distributed_sequence_column(
| 1| b|
| 2| c|
+--------+---+
- >>> force_nullable
- True
"""
if len(sdf.columns) > 0:
- try:
- jdf = sdf._jdf.toDF() # type: ignore
-
- sql_ctx = sdf.sql_ctx
- encoders = sql_ctx._jvm.org.apache.spark.sql.Encoders # type:
ignore
- encoder = encoders.tuple(jdf.exprEnc(), encoders.scalaLong())
-
- jrdd = jdf.localCheckpoint(False).rdd().zipWithIndex()
-
- df = SparkDataFrame(
- sql_ctx.sparkSession._jsparkSession.createDataset( #
type: ignore
- jrdd, encoder
- ).toDF(),
- sql_ctx,
- )
- columns = df.columns
- return (
- df.selectExpr(
- "`{}` as `{}`".format(columns[1], column_name),
"`{}`.*".format(columns[0])
- ),
- True,
- )
- except py4j.protocol.Py4JError:
- if is_testing():
- raise
- return InternalFrame._attach_distributed_sequence_column(sdf,
column_name)
+ return SparkDataFrame(
+ sdf._jdf.toDF().withSequenceColumn(column_name), # type:
ignore
+ sdf.sql_ctx,
+ )
else:
cnt = sdf.count()
if cnt > 0:
- return default_session().range(cnt).toDF(column_name), False
+ return default_session().range(cnt).toDF(column_name)
else:
- return (
- default_session().createDataFrame(
- [],
- schema=StructType().add(column_name,
data_type=LongType(), nullable=False),
- ),
- False,
+ return default_session().createDataFrame(
+ [], schema=StructType().add(column_name,
data_type=LongType(), nullable=False)
)
- @staticmethod
- def _attach_distributed_sequence_column(
Review comment:
We don't need this anymore. This one was a hack for Databricks only.
--
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]