@@ -1529,23 +1529,41 @@ cleanup_old_snapshots("analytics.user_events", [12345, 67890, 11111])
15291529
15301530## Create a view
15311531
1532- To create a view from a catalog:
1532+ If the REST server does not indicate support for view endpoints, you can enable it by setting ` "view-endpoints-supported": "true" ` :
1533+
1534+ ``` python
1535+ from pyiceberg.catalog import load_catalog
1536+
1537+ catalog = load_catalog(
1538+ " docs" ,
1539+ ** {
1540+ " uri" : " http://127.0.0.1:8181" ,
1541+ " s3.endpoint" : " http://127.0.0.1:9000" ,
1542+ " py-io-impl" : " pyiceberg.io.pyarrow.PyArrowFileIO" ,
1543+ " s3.access-key-id" : " admin" ,
1544+ " s3.secret-access-key" : " password" ,
1545+ " view-endpoints-supported" : " true" ,
1546+ }
1547+ )
1548+ ```
1549+
1550+ To create a view from the catalog:
15331551
15341552``` python
15351553import time
1536- import pyarrow as pa
15371554from pyiceberg.catalog import load_catalog
1555+ from pyiceberg.schema import Schema
1556+ from pyiceberg.types import IntegerType, NestedField
15381557from pyiceberg.view import SQLViewRepresentation, ViewVersion
15391558
15401559catalog = load_catalog(" default" )
15411560
1542- identifier = " default.some_view"
1543- schema = pa.schema([pa.field(" some_col" , pa.int32())])
1561+ schema = Schema(NestedField(field_id = 1 , name = " some_col" , field_type = IntegerType(), required = False ))
15441562view_version = ViewVersion(
15451563 version_id = 1 ,
15461564 schema_id = 1 ,
15471565 timestamp_ms = int (time.time() * 1000 ),
1548- summary = {},
1566+ summary = {" spark-version " : " 4.1 " },
15491567 representations = [
15501568 SQLViewRepresentation(
15511569 type = " sql" ,
@@ -1557,7 +1575,21 @@ view_version = ViewVersion(
15571575)
15581576
15591577catalog.create_view(
1560- identifier = identifier,
1578+ identifier = " default.some_view" ,
1579+ schema = schema,
1580+ view_version = view_version,
1581+ )
1582+ ```
1583+
1584+ ` catalog.create_view ` also accepts a PyArrow schema, so the following is equivalent:
1585+
1586+ ``` python
1587+ import pyarrow as pa
1588+
1589+ schema = pa.schema([pa.field(" some_col" , pa.int32())])
1590+
1591+ catalog.create_view(
1592+ identifier = " default.some_view" ,
15611593 schema = schema,
15621594 view_version = view_version,
15631595)
0 commit comments