rambleraptor commented on code in PR #41: URL: https://github.com/apache/terraform-provider-iceberg/pull/41#discussion_r3375291644
########## internal/provider/table_metadata_sync.go: ########## @@ -0,0 +1,86 @@ +// 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 provider + +import ( + "context" + + "github.com/apache/iceberg-go/table" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// icebergTableMetadataFields holds Terraform values synced from an Iceberg table's metadata +// (schema, partition spec, sort order, properties). Used by the table resource and table data source. +type icebergTableMetadataFields struct { + Schema types.Object + PartitionSpec types.Object + SortOrder types.Object + ServerProperties types.Map +} + +func syncIcebergTableMetadataToModel(ctx context.Context, tbl *table.Table, out *icebergTableMetadataFields, diags *diag.Diagnostics) { Review Comment: Love being able to reuse this as well. ########## internal/provider/table_tfschema.go: ########## @@ -0,0 +1,424 @@ +// 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 provider + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + rscschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +const tableSchemaFieldMaxDepth = 4 + +func tableSchemaResourceAttributes() map[string]rscschema.Attribute { Review Comment: I love this! It's great that we can reuse them. (This didn't use to be the case in older versions of the Terraform SDK I believe) ########## README.md: ########## @@ -19,12 +19,17 @@ This [Terraform](https://terraform.io) and [OpenTofu](https://www.opentofu.org/) provider allows you to manage Iceberg resources, such as namespaces and tables. -## Supported Resources +## Supported Data Sources + +- `iceberg_table`: Read metadata for an existing table (schema, partition spec, sort order, and catalog properties). -The provider currently supports the following resources: +## Supported Resources - `iceberg_namespace`: Manage Iceberg namespaces and their properties. - `iceberg_table`: Manage Iceberg tables, including schema definitions and properties. +- `iceberg_polaris_principal`: Manage Polaris principals and client credentials (when using a Polaris catalog). Review Comment: Thanks for adding this in! ########## docs/data-sources/table.md: ########## @@ -0,0 +1,115 @@ +--- +page_title: "iceberg_table Data Source - Iceberg" +subcategory: "" +description: |- + Reads metadata for an existing Iceberg table from the catalog. +--- + +<!-- + - 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. + --> + +# iceberg_table (Data Source) + +Reads metadata for an existing Iceberg table from the catalog. + +Use this data source to inspect tables created outside Terraform, to reference tables managed in another workspace, or to read the current catalog state of a table also managed by an [`iceberg_table` resource](../resources/table.md). + +## Example Usage + +### Read a table by namespace and name + +```terraform +// Licensed to the Apache Software Foundation (ASF) under one or more Review Comment: I don't think we need this second set of Apache license headers here ########## internal/provider/table_metadata_sync.go: ########## @@ -0,0 +1,86 @@ +// 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 provider + +import ( + "context" + + "github.com/apache/iceberg-go/table" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// icebergTableMetadataFields holds Terraform values synced from an Iceberg table's metadata +// (schema, partition spec, sort order, properties). Used by the table resource and table data source. +type icebergTableMetadataFields struct { + Schema types.Object + PartitionSpec types.Object + SortOrder types.Object + ServerProperties types.Map +} + +func syncIcebergTableMetadataToModel(ctx context.Context, tbl *table.Table, out *icebergTableMetadataFields, diags *diag.Diagnostics) { Review Comment: nit: could we call this `convert` instead of `sync`? Sync makes me think that we're making some underlying changes rather than just converting the data from one structure to another. ########## Makefile: ########## @@ -15,6 +15,10 @@ .PHONY: test-integration test-integration-setup test-integration-exec test-integration-cleanup +test-integration: ## Start Docker services, run integration tests, then tear down + @$(MAKE) test-integration-setup Review Comment: Is there a reason not just to list the three commands? -- 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]
