org.apache.iceberg.spark.SparkUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iceberg-spark Show documentation
Show all versions of iceberg-spark Show documentation
A table format for huge analytic datasets
/*
* 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 org.apache.iceberg.spark;
import java.util.stream.Collectors;
import org.apache.iceberg.PartitionField;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Table;
import org.apache.iceberg.hadoop.HadoopFileIO;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.transforms.Transform;
import org.apache.iceberg.transforms.UnknownTransform;
import org.apache.spark.util.SerializableConfiguration;
public class SparkUtil {
private SparkUtil() {
}
public static FileIO serializableFileIO(Table table) {
if (table.io() instanceof HadoopFileIO) {
// we need to use Spark's SerializableConfiguration to avoid issues with Kryo serialization
SerializableConfiguration conf = new SerializableConfiguration(((HadoopFileIO) table.io()).conf());
return new HadoopFileIO(conf::value);
} else {
return table.io();
}
}
/**
* Check whether the partition transforms in a spec can be used to write data.
*
* @param spec a PartitionSpec
* @throws UnsupportedOperationException if the spec contains unknown partition transforms
*/
public static void validatePartitionTransforms(PartitionSpec spec) {
if (spec.fields().stream().anyMatch(field -> field.transform() instanceof UnknownTransform)) {
String unsupported = spec.fields().stream()
.map(PartitionField::transform)
.filter(transform -> transform instanceof UnknownTransform)
.map(Transform::toString)
.collect(Collectors.joining(", "));
throw new UnsupportedOperationException(
String.format("Cannot write using unsupported transforms: %s", unsupported));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy