PySpark APIs 支持 Snowpark Connect for Spark

如本主题中所述,Snowpark Connect for Spark 支持 PySpark APIs。

Snowpark Connect for Spark 兼容 PySpark 3.5.3 Spark Connect API,允许您在 Snowflake 上运行 Spark 工作负载。Snowpark Connect for Spark 兼容性由运行使用 Pyspark 3.5.3 Spark Connect API 的 Spark 应用程序时的执行行为定义。本指南详细介绍了支持哪些 APIs 及其兼容性级别。

兼容级别定义

完全兼容 APIs

完全兼容的 APIs 行为与原生 PySpark 相同。您可以安心使用这些 APIs,结果将完全匹配。

高兼容性 APIs

高兼容性 APIs 可以正常工作,但可能会有细微差别:

  • 错误消息格式可能有所不同。

  • 输出显示格式可能会有所不同(例如小数精度、列名大小写)。

  • 边缘情况产生的结果可能会略有不同。

部分兼容 APIs

部分兼容 APIs 可以正常运行,但具有明显的局限性:

  • 可能只有一部分功能可用。

  • 在特定场景中,行为可能与 PySpark 不同。

  • 可能需要额外配置。

  • 性能特征可能有所不同。

不支持的 APIs

目前尚未实施或在 Snowflake 上不受支持的 APIs。

DataFrame APIs

核心 DataFrame API 覆盖范围。

完全兼容 APIs

  • cache

  • coalesce

  • collect

  • count

  • crossJoin

  • dropDuplicates

  • drop_duplicates

  • dropna

  • fillna

  • first

  • head

  • isEmpty

  • join

  • limit

  • melt

  • offset

  • persist

  • repartitionByRange

  • replace

  • select

  • show

  • tail

  • take

  • toDF

  • toLocalIterator

  • toPandas

  • unionAll

  • unpersist

  • unpivot

  • where

  • withColumnsRenamed

  • toLocalIterator

  • toPandas

  • unionAll

  • unpersist

  • unpivot

  • where

  • withColumnsRenamed

高兼容性 APIs

  • agg

  • colRegex

  • corr

  • cov

  • crosstab

  • cube

  • describe

  • distinct

  • drop

  • exceptAll

  • groupBy

  • groupby

  • intersect

  • intersectAll

  • isLocal

  • mapInPandas

  • orderBy

  • rollup

  • sort

  • union

  • unionByName

  • withColumn

备注

  • orderBy / sort:从链中最后一个 DataFrame 推断出的列顺序。

  • union / unionByName:类型扩展行为可能略有不同。

  • describe:选择使用 时默认使用的角色和仓库。统计输出格式可能会有所不同。

部分兼容 APIs

  • alias

  • approxQuantile

  • createGlobalTempView

  • createOrReplaceGlobalTempView

  • createOrReplaceTempView

  • createTempView

  • explain

  • filter

  • freqItems

  • hint

  • inputFiles

  • printSchema

  • randomSplit

  • repartition

  • sameSemantics

  • sample

  • sampleBy

  • selectExpr

  • semanticHash

  • sortWithinPartitions

  • subtract

  • summary

  • transform

  • withColumns

  • withMetadata

备注

  • explain:选择使用 时默认使用的角色和仓库。查询计划格式与 Spark 不同。

  • repartition:选择使用 时默认使用的角色和仓库。分区计数可能不准确。

  • sample:选择使用 时默认使用的角色和仓库。随机采样实施有所不同。

  • createTempView:选择使用 时默认使用的角色和仓库。视图生命周期可能有所不同。

不支持的 APIs

  • checkSameSparkSession

  • dropDuplicatesWithinWatermark

  • observe

  • pandas_api

  • registerTempTable

  • to_pandas_on_spark

  • withWatermark

列 APIs

列操作的覆盖范围。

完全兼容 APIs

  • asc

  • between

  • contains

  • desc

  • eqNullSafe

  • getItem

  • isNull

  • isin

  • like

  • otherwise

  • startswith

  • substr

  • when

高兼容性 APIs

  • alias

  • asc_nulls_first

  • asc_nulls_last

  • astype

  • bitwiseAND

  • bitwiseOR

  • bitwiseXOR

  • cast

  • desc_nulls_first

  • desc_nulls_last

  • endswith

  • isNotNull

备注

  • cast:选择使用 时默认使用的角色和仓库。一些无效的转换在 Spark 中会返回 NULL,但在 Snowpark 中会出错。

  • alias:选择使用 时默认使用的角色和仓库。结构字段显示格式可能有所不同。

部分兼容 APIs

  • dropFields

  • ilike

  • over

  • rlike

  • withField

备注

  • over:选择使用 时默认使用的角色和仓库。窗口框架规格可能存在细微差异。

  • rlike:选择使用 时默认使用的角色和仓库。正则表达式语法遵循 Snowflake 约定。

SparkSession APIs

完全兼容 APIs

  • range

  • sql

  • table

高兼容性 APIs

  • createDataFrame

备注

架构推理可能会生成不同的类型(例如 NUMBER(38,0)LONG)。

部分兼容 APIs

  • addArtifact

  • addArtifacts

  • addTag

  • clearTags

  • getTags

  • interruptAll

  • interruptOperation

  • interruptTag

  • removeTag

备注

  • 标签映射到 Snowflake 查询标签。

  • 中断操作使用 Snowflake 查询 IDs 而不是操作 IDs.

不支持的 APIs

  • copyFromLocalToFs

  • stop

GroupedData APIs

完全兼容 APIs

  • agg

  • mean

  • pivot

高兼容性 APIs

  • agg

  • mean

  • pivot

部分兼容 APIs

  • apply

  • avg

  • sum

不支持的 APIs

  • applyInPandasWithState

  • cogroup

DataFrameReader APIs

完全兼容 APIs

  • table

高兼容性 APIs

  • csv

部分兼容 APIs

  • json

  • load

  • parquet

  • jdbc

备注

  • 文件路径使用 Snowflake 暂存区或云存储(S3、GCS、Azure)。

  • 架构推理可能与原生 Spark 不同。

  • 可能不支持某些特定格式的选项。

不支持的 APIs

  • orc

DataFrameWriter APIs

完全兼容 APIs

  • mode

  • saveAsTable

  • text

部分兼容 APIs

  • csv

  • json

  • options

  • parquet

备注

  • 写入将转到 Snowflake 暂存区或云存储。

  • 分区行为可能有所不同。

不支持的 APIs

  • bucketBy

  • insertInto

  • jdbc

  • orc

  • sortBy

DataFrameWriterV2 APIs

较新版本 DataFrameWriterV2 API 的覆盖范围。

完全兼容 APIs

  • replace

部分兼容 APIs

  • append

  • create

  • createOrReplace

  • option

  • options

  • partitionedBy

  • tableProperty

  • using

目录 APIs

完全兼容 APIs

  • cacheTable

  • clearCache

  • dropGlobalTempView

  • dropTempView

  • isCached

  • refreshByPath

  • refreshTable

  • uncacheTable

高兼容性 APIs

  • currentCatalog

  • listCatalogs

  • listColumns

  • recoverPartitions

  • setCurrentCatalog

备注

  • listColumns:选择使用 时默认使用的角色和仓库。列名称大写,类型为 Snowflake 特定类型。

  • 错误消息的格式可能有所不同。

不支持的 APIs

  • createExternalTable

  • createTable

  • functionExists

  • getFunction

  • listFunctions

  • registerFunction

窗口和 WindowSpec APIs

窗口函数的覆盖范围。

窗口(全量 D0)APIs

  • partitionBy

  • orderBy

  • rangeBetween

  • rowsBetween

  • unboundedPreceding

  • unboundedFollowing

  • currentRow

WindowSpec(全量 D0)APIs

  • partitionBy

  • orderBy

  • rangeBetween

  • rowsBetween

语言: 中文