Skip to content

Commit

Permalink
Extract the common namespace and schema as fixtures for the shared tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Jan 31, 2025
1 parent 0d995da commit 7fb4d98
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::{Arc, OnceLock};
use ctor::dtor;
use iceberg_integration_tests::{set_test_fixture, TestFixture};

pub mod shared;
pub mod shared_tests;

static DOCKER_CONTAINERS: OnceLock<Arc<TestFixture>> = OnceLock::new();

Expand Down
24 changes: 0 additions & 24 deletions crates/integration_tests/tests/shared/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,34 @@

//! Integration tests for rest catalog.
use std::collections::HashMap;
use std::sync::Arc;

use arrow_array::{ArrayRef, BooleanArray, Int32Array, RecordBatch, StringArray};
use futures::TryStreamExt;
use iceberg::spec::{NestedField, PrimitiveType, Schema, Type};
use iceberg::transaction::Transaction;
use iceberg::writer::base_writer::data_file_writer::DataFileWriterBuilder;
use iceberg::writer::file_writer::location_generator::{
DefaultFileNameGenerator, DefaultLocationGenerator,
};
use iceberg::writer::file_writer::ParquetWriterBuilder;
use iceberg::writer::{IcebergWriter, IcebergWriterBuilder};
use iceberg::{Catalog, Namespace, NamespaceIdent, TableCreation};
use iceberg::{Catalog, TableCreation};
use iceberg_catalog_rest::RestCatalog;
use parquet::arrow::arrow_reader::ArrowReaderOptions;
use parquet::file::properties::WriterProperties;

use crate::get_shared_containers;
use crate::shared_tests::{apple_ios_ns, test_schema};

#[tokio::test]
async fn test_append_data_file() {
let fixture = get_shared_containers();
let rest_catalog = RestCatalog::new(fixture.catalog_config.clone());

let ns = Namespace::with_properties(
NamespaceIdent::from_strs(["apple", "ios"]).unwrap(),
HashMap::from([
("owner".to_string(), "ray".to_string()),
("community".to_string(), "apache".to_string()),
]),
);

let _ = rest_catalog
.create_namespace(ns.name(), ns.properties().clone())
.await;

let schema = Schema::builder()
.with_schema_id(1)
.with_identifier_field_ids(vec![2])
.with_fields(vec![
NestedField::optional(1, "foo", Type::Primitive(PrimitiveType::String)).into(),
NestedField::required(2, "bar", Type::Primitive(PrimitiveType::Int)).into(),
NestedField::optional(3, "baz", Type::Primitive(PrimitiveType::Boolean)).into(),
])
.build()
.unwrap();
let ns = apple_ios_ns().await;
let schema = test_schema();

let table_creation = TableCreation::builder()
.name("t1".to_string())
.name("t_append_data_file".to_string())
.schema(schema.clone())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@

//! Integration test for partition data file
use std::collections::HashMap;
use std::sync::Arc;

use arrow_array::{ArrayRef, BooleanArray, Int32Array, RecordBatch, StringArray};
use futures::TryStreamExt;
use iceberg::spec::{
Literal, NestedField, PrimitiveLiteral, PrimitiveType, Schema, Struct, Transform, Type,
UnboundPartitionSpec,
};
use iceberg::spec::{Literal, PrimitiveLiteral, Struct, Transform, UnboundPartitionSpec};
use iceberg::table::Table;
use iceberg::transaction::Transaction;
use iceberg::writer::base_writer::data_file_writer::DataFileWriterBuilder;
Expand All @@ -34,39 +30,19 @@ use iceberg::writer::file_writer::location_generator::{
};
use iceberg::writer::file_writer::ParquetWriterBuilder;
use iceberg::writer::{IcebergWriter, IcebergWriterBuilder};
use iceberg::{Catalog, Namespace, NamespaceIdent, TableCreation};
use iceberg::{Catalog, TableCreation};
use iceberg_catalog_rest::RestCatalog;
use parquet::file::properties::WriterProperties;

use crate::get_shared_containers;
use crate::shared_tests::{apple_ios_ns, test_schema};

#[tokio::test]
async fn test_append_partition_data_file() {
let fixture = get_shared_containers();
let rest_catalog = RestCatalog::new(fixture.catalog_config.clone());

let ns = Namespace::with_properties(
NamespaceIdent::from_strs(["iceberg", "rust"]).unwrap(),
HashMap::from([
("owner".to_string(), "ray".to_string()),
("community".to_string(), "apache".to_string()),
]),
);

let _ = rest_catalog
.create_namespace(ns.name(), ns.properties().clone())
.await;

let schema = Schema::builder()
.with_schema_id(1)
.with_identifier_field_ids(vec![2])
.with_fields(vec![
NestedField::optional(1, "foo", Type::Primitive(PrimitiveType::String)).into(),
NestedField::required(2, "bar", Type::Primitive(PrimitiveType::Int)).into(),
NestedField::optional(3, "baz", Type::Primitive(PrimitiveType::Boolean)).into(),
])
.build()
.unwrap();
let ns = apple_ios_ns().await;
let schema = test_schema();

let unbound_partition_spec = UnboundPartitionSpec::builder()
.add_partition_field(2, "id", Transform::Identity)
Expand All @@ -78,7 +54,7 @@ async fn test_append_partition_data_file() {
.expect("could not bind to schema");

let table_creation = TableCreation::builder()
.name("t2".to_string())
.name("t_append_partition_data_file".to_string())
.schema(schema.clone())
.partition_spec(partition_spec)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,30 @@

//! Integration tests for rest catalog.
use std::collections::HashMap;
use std::sync::Arc;

use arrow_array::{ArrayRef, BooleanArray, Int32Array, RecordBatch, StringArray};
use futures::TryStreamExt;
use iceberg::spec::{NestedField, PrimitiveType, Schema, Type};
use iceberg::transaction::Transaction;
use iceberg::writer::base_writer::data_file_writer::DataFileWriterBuilder;
use iceberg::writer::file_writer::location_generator::{
DefaultFileNameGenerator, DefaultLocationGenerator,
};
use iceberg::writer::file_writer::ParquetWriterBuilder;
use iceberg::writer::{IcebergWriter, IcebergWriterBuilder};
use iceberg::{Catalog, Namespace, NamespaceIdent, TableCreation};
use iceberg::{Catalog, TableCreation};
use iceberg_catalog_rest::RestCatalog;
use parquet::file::properties::WriterProperties;

use crate::get_shared_containers;
use crate::shared_tests::{apple_ios_ns, test_schema};

#[tokio::test]
async fn test_append_data_file_conflict() {
let fixture = get_shared_containers();
let rest_catalog = RestCatalog::new(fixture.catalog_config.clone());

let ns = Namespace::with_properties(
NamespaceIdent::from_strs(["apple", "ios"]).unwrap(),
HashMap::from([
("owner".to_string(), "ray".to_string()),
("community".to_string(), "apache".to_string()),
]),
);

let _ = rest_catalog
.create_namespace(ns.name(), ns.properties().clone())
.await;

let schema = Schema::builder()
.with_schema_id(1)
.with_identifier_field_ids(vec![2])
.with_fields(vec![
NestedField::optional(1, "foo", Type::Primitive(PrimitiveType::String)).into(),
NestedField::required(2, "bar", Type::Primitive(PrimitiveType::Int)).into(),
NestedField::optional(3, "baz", Type::Primitive(PrimitiveType::Boolean)).into(),
])
.build()
.unwrap();
let ns = apple_ios_ns().await;
let schema = test_schema();

let table_creation = TableCreation::builder()
.name("t3".to_string())
Expand Down
73 changes: 73 additions & 0 deletions crates/integration_tests/tests/shared_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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.

use std::collections::HashMap;
use std::sync::Arc;

use iceberg::spec::{NestedField, PrimitiveType, Schema, Type};
use iceberg::{Catalog, Namespace, NamespaceIdent};
use iceberg_catalog_rest::RestCatalog;
use tokio::sync::OnceCell;

use crate::get_shared_containers;

mod append_data_file_test;
mod append_partition_data_file_test;
mod conflict_commit_test;
mod datafusion;
mod read_evolved_schema;
mod read_positional_deletes;
mod scan_all_type;

static TEST_NAMESPACE: OnceCell<Arc<Namespace>> = OnceCell::const_new();

pub async fn apple_ios_ns() -> &'static Arc<Namespace> {
TEST_NAMESPACE
.get_or_init(|| async {
let fixture = get_shared_containers();
let rest_catalog = RestCatalog::new(fixture.catalog_config.clone());

let ns = Namespace::with_properties(
NamespaceIdent::from_strs(["apple", "ios"]).unwrap(),
HashMap::from([
("owner".to_string(), "ray".to_string()),
("community".to_string(), "apache".to_string()),
]),
);

rest_catalog
.create_namespace(ns.name(), ns.properties().clone())
.await
.unwrap();

Arc::new(ns)
})
.await
}

fn test_schema() -> Schema {
Schema::builder()
.with_schema_id(1)
.with_identifier_field_ids(vec![2])
.with_fields(vec![
NestedField::optional(1, "foo", Type::Primitive(PrimitiveType::String)).into(),
NestedField::required(2, "bar", Type::Primitive(PrimitiveType::Int)).into(),
NestedField::optional(3, "baz", Type::Primitive(PrimitiveType::Boolean)).into(),
])
.build()
.unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,21 @@ use iceberg::writer::file_writer::location_generator::{
};
use iceberg::writer::file_writer::ParquetWriterBuilder;
use iceberg::writer::{IcebergWriter, IcebergWriterBuilder};
use iceberg::{Catalog, Namespace, NamespaceIdent, TableCreation};
use iceberg::{Catalog, TableCreation};
use iceberg_catalog_rest::RestCatalog;
use parquet::arrow::PARQUET_FIELD_ID_META_KEY;
use parquet::file::properties::WriterProperties;
use uuid::Uuid;

use crate::get_shared_containers;
use crate::shared_tests::apple_ios_ns;

#[tokio::test]
async fn test_scan_all_type() {
let fixture = get_shared_containers();
let rest_catalog = RestCatalog::new(fixture.catalog_config.clone());
let ns = apple_ios_ns().await;

let ns = Namespace::with_properties(
NamespaceIdent::from_strs(["apple", "ios"]).unwrap(),
HashMap::from([
("owner".to_string(), "ray".to_string()),
("community".to_string(), "apache".to_string()),
]),
);

let _ = rest_catalog
.create_namespace(ns.name(), ns.properties().clone())
.await;
let schema = Schema::builder()
.with_schema_id(1)
.with_identifier_field_ids(vec![2])
Expand Down Expand Up @@ -134,7 +125,7 @@ async fn test_scan_all_type() {
.unwrap();

let table_creation = TableCreation::builder()
.name("t4".to_string())
.name("t_scan_all_types".to_string())
.schema(schema.clone())
.build();

Expand Down

0 comments on commit 7fb4d98

Please sign in to comment.