|
| 1 | +/* |
| 2 | + * Copyright 2024 Netflix, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.netflix.metacat.connector.hive.iceberg |
| 18 | + |
| 19 | +import org.apache.iceberg.BaseMetastoreTableOperations |
| 20 | +import org.apache.iceberg.ScanSummary |
| 21 | +import org.apache.iceberg.Schema |
| 22 | +import org.apache.iceberg.UpdateSchema |
| 23 | +import org.apache.iceberg.TableMetadata |
| 24 | +import org.apache.iceberg.TableMetadataParser |
| 25 | +import org.apache.iceberg.types.Types |
| 26 | +import spock.lang.Specification |
| 27 | + |
| 28 | +/** |
| 29 | + * Simple validation tests to ensure Iceberg 1.1.0 upgrade is working correctly. |
| 30 | + * These tests focus on API compatibility and version verification. |
| 31 | + */ |
| 32 | +class IcebergVersionValidationSpec extends Specification { |
| 33 | + |
| 34 | + def "test Iceberg 1.1.0 API classes are available"() { |
| 35 | + expect: "All critical Iceberg classes should be available" |
| 36 | + Class.forName('org.apache.iceberg.ScanSummary') != null |
| 37 | + Class.forName('org.apache.iceberg.Table') != null |
| 38 | + Class.forName('org.apache.iceberg.TableMetadataParser') != null |
| 39 | + Class.forName('org.apache.iceberg.UpdateSchema') != null |
| 40 | + Class.forName('org.apache.iceberg.BaseMetastoreTableOperations') != null |
| 41 | + Class.forName('org.apache.iceberg.hadoop.HadoopFileIO') != null |
| 42 | + } |
| 43 | + |
| 44 | + def "test ScanSummary.PartitionMetrics constructor works"() { |
| 45 | + when: "Create PartitionMetrics using Iceberg 1.1.0 constructor" |
| 46 | + def metrics = new ScanSummary.PartitionMetrics( |
| 47 | + fileCount: 10, |
| 48 | + recordCount: 1000, |
| 49 | + dataTimestampMillis: System.currentTimeMillis() |
| 50 | + ) |
| 51 | + |
| 52 | + then: "Should create successfully" |
| 53 | + metrics != null |
| 54 | + metrics.fileCount() == 10 |
| 55 | + metrics.recordCount() == 1000 |
| 56 | + metrics.dataTimestampMillis() != null |
| 57 | + } |
| 58 | + |
| 59 | + def "test Schema creation and field access works"() { |
| 60 | + when: "Create Iceberg schema using 1.1.0 API" |
| 61 | + def schema = new Schema([ |
| 62 | + Types.NestedField.required(1, "id", Types.LongType.get()), |
| 63 | + Types.NestedField.optional(2, "name", Types.StringType.get(), "Test comment"), |
| 64 | + Types.NestedField.optional(3, "value", Types.DoubleType.get()) |
| 65 | + ]) |
| 66 | + |
| 67 | + then: "Schema should be created correctly" |
| 68 | + schema != null |
| 69 | + schema.columns().size() == 3 |
| 70 | + schema.findField("name").doc() == "Test comment" |
| 71 | + schema.findField("id").isRequired() |
| 72 | + schema.findField("name").isOptional() |
| 73 | + } |
| 74 | + |
| 75 | + def "test TableMetadataParser API exists"() { |
| 76 | + expect: "TableMetadataParser.toJson method should exist" |
| 77 | + def method = TableMetadataParser.class.getDeclaredMethod('toJson', TableMetadata.class) |
| 78 | + method != null |
| 79 | + method.getReturnType() == String.class |
| 80 | + } |
| 81 | + |
| 82 | + def "test UpdateSchema API exists"() { |
| 83 | + expect: "UpdateSchema should have expected methods" |
| 84 | + def updateColumnDocMethod = UpdateSchema.class.getDeclaredMethod('updateColumnDoc', String.class, String.class) |
| 85 | + updateColumnDocMethod != null |
| 86 | + |
| 87 | + // Check if commit method exists (might be inherited or have different signature) |
| 88 | + def commitMethods = UpdateSchema.class.getMethods().findAll { it.name == 'commit' } |
| 89 | + commitMethods.size() > 0 |
| 90 | + } |
| 91 | + |
| 92 | + def "test BaseMetastoreTableOperations methods exist"() { |
| 93 | + expect: "BaseMetastoreTableOperations should have expected methods" |
| 94 | + def ioMethods = BaseMetastoreTableOperations.class.getMethods().findAll { it.name == 'io' } |
| 95 | + ioMethods.size() > 0 |
| 96 | + |
| 97 | + def currentMethods = BaseMetastoreTableOperations.class.getMethods().findAll { it.name == 'current' } |
| 98 | + currentMethods.size() > 0 |
| 99 | + currentMethods.any { it.returnType == TableMetadata.class } |
| 100 | + } |
| 101 | + |
| 102 | + def "test Table refs method exists for branching support"() { |
| 103 | + expect: "Table should have refs() method for branching and tagging functionality" |
| 104 | + def tableClass = Class.forName('org.apache.iceberg.Table') |
| 105 | + def refsMethods = tableClass.getMethods().findAll { it.name == 'refs' } |
| 106 | + refsMethods.size() > 0 |
| 107 | + |
| 108 | + // Verify the method returns something that could be table references |
| 109 | + def refsMethod = refsMethods.first() |
| 110 | + refsMethod.returnType != null |
| 111 | + refsMethod.parameterCount == 0 |
| 112 | + } |
| 113 | + |
| 114 | + def "test version detection"() { |
| 115 | + when: "Check Iceberg version information" |
| 116 | + def icebergVersion = getIcebergVersionInfo() |
| 117 | + |
| 118 | + then: "Should indicate we're using version 1.x" |
| 119 | + println "Iceberg version info: ${icebergVersion}" |
| 120 | + icebergVersion.contains("1.") |
| 121 | + !icebergVersion.contains("0.13.1") && !icebergVersion.contains("pre-1.0") // Should not be the older than 1.1 |
| 122 | + } |
| 123 | + |
| 124 | + private String getIcebergVersionInfo() { |
| 125 | + try { |
| 126 | + // Try to get version from package |
| 127 | + def packageInfo = Package.getPackage("org.apache.iceberg") |
| 128 | + if (packageInfo?.implementationVersion) { |
| 129 | + return "Package version: ${packageInfo.implementationVersion}" |
| 130 | + } |
| 131 | + |
| 132 | + // Check for new 1.1+ features that didn't exist in 0.13 |
| 133 | + try { |
| 134 | + // This class exists in Iceberg 1.0+ |
| 135 | + Class.forName("org.apache.iceberg.actions.RewriteDataFiles") |
| 136 | + return "1.0+ (has RewriteDataFiles)" |
| 137 | + } catch (ClassNotFoundException e) { |
| 138 | + // This means we're on an older version |
| 139 | + return "pre-1.0" |
| 140 | + } |
| 141 | + } catch (Exception e) { |
| 142 | + return "unknown: ${e.message}" |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments