Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Specifies the input schema. Some data sources (such as JSON) can infer the input schema automatically from data. By specifying the schema here, the underlying data source can skip the schema inference step, which speeds up data loading.
Syntax
schema(schema)
Parameters
| Parameter | Type | Description |
|---|---|---|
schema |
StructType or str | A StructType object or a DDL-formatted string (for example, 'col0 INT, col1 DOUBLE'). |
Returns
DataFrameReader
Examples
Specify the schema when reading a CSV file.
import tempfile
with tempfile.TemporaryDirectory(prefix="schema") as d:
spark.read.schema("col0 INT, col1 DOUBLE").format("csv").load(d).printSchema()
# root
# |-- col0: integer (nullable = true)
# |-- col1: double (nullable = true)