-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-12078: Add JDBC Catalog Controller Service for Iceberg processors
Disable jdbc catalog tests on Windows OS Fix review comments Signed-off-by: Matt Burgess <[email protected]> This closes #9145
- Loading branch information
1 parent
6013b93
commit f31f803
Showing
24 changed files
with
687 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ommon/src/main/java/org/apache/nifi/processors/iceberg/catalog/IcebergJdbcClientPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.nifi.processors.iceberg.catalog; | ||
|
||
import org.apache.iceberg.jdbc.JdbcClientPool; | ||
import org.apache.nifi.dbcp.DBCPService; | ||
|
||
import java.sql.Connection; | ||
import java.util.Map; | ||
|
||
public class IcebergJdbcClientPool extends JdbcClientPool { | ||
|
||
private final DBCPService dbcpService; | ||
|
||
public IcebergJdbcClientPool(Map<String, String> properties, DBCPService dbcpService) { | ||
super("", properties); | ||
this.dbcpService = dbcpService; | ||
} | ||
|
||
@Override | ||
protected Connection newClient() { | ||
return dbcpService.getConnection(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...g-processors/src/test/java/org/apache/nifi/processors/iceberg/AbstractTestPutIceberg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.nifi.processors.iceberg; | ||
|
||
import org.apache.avro.Schema; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.iceberg.catalog.Catalog; | ||
import org.apache.iceberg.catalog.TableIdentifier; | ||
import org.apache.iceberg.types.Types; | ||
import org.apache.nifi.avro.AvroTypeUtil; | ||
import org.apache.nifi.reporting.InitializationException; | ||
import org.apache.nifi.serialization.record.MockRecordParser; | ||
import org.apache.nifi.serialization.record.RecordField; | ||
import org.apache.nifi.serialization.record.RecordSchema; | ||
import org.apache.nifi.util.TestRunner; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
import static org.apache.nifi.processors.iceberg.util.IcebergTestUtils.NAMESPACE; | ||
import static org.apache.nifi.processors.iceberg.util.IcebergTestUtils.RECORD_READER_SERVICE; | ||
import static org.apache.nifi.processors.iceberg.util.IcebergTestUtils.createTemporaryDirectory; | ||
|
||
public class AbstractTestPutIceberg { | ||
|
||
protected static final String TABLE_NAME = "users"; | ||
|
||
protected static final TableIdentifier TABLE_IDENTIFIER = TableIdentifier.of(NAMESPACE, TABLE_NAME); | ||
|
||
protected static final org.apache.iceberg.Schema USER_SCHEMA = new org.apache.iceberg.Schema( | ||
Types.NestedField.required(1, "id", Types.IntegerType.get()), | ||
Types.NestedField.required(2, "name", Types.StringType.get()), | ||
Types.NestedField.required(3, "department", Types.StringType.get()) | ||
); | ||
|
||
protected TestRunner runner; | ||
protected PutIceberg processor; | ||
protected Catalog catalog; | ||
protected String warehousePath; | ||
protected static Schema inputSchema; | ||
|
||
protected void initRecordReader() throws InitializationException { | ||
final MockRecordParser readerFactory = new MockRecordParser(); | ||
final RecordSchema recordSchema = AvroTypeUtil.createSchema(inputSchema); | ||
|
||
for (RecordField recordField : recordSchema.getFields()) { | ||
readerFactory.addSchemaField(recordField); | ||
} | ||
|
||
readerFactory.addRecord(0, "John", "Finance"); | ||
readerFactory.addRecord(1, "Jill", "Finance"); | ||
readerFactory.addRecord(2, "James", "Marketing"); | ||
readerFactory.addRecord(3, "Joana", "Sales"); | ||
|
||
runner.addControllerService(RECORD_READER_SERVICE, readerFactory); | ||
runner.enableControllerService(readerFactory); | ||
|
||
runner.setProperty(PutIceberg.RECORD_READER, RECORD_READER_SERVICE); | ||
} | ||
|
||
@BeforeAll | ||
public static void initSchema() throws IOException { | ||
final String avroSchema = IOUtils.toString(Files.newInputStream(Paths.get("src/test/resources/user.avsc")), StandardCharsets.UTF_8); | ||
inputSchema = new Schema.Parser().parse(avroSchema); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
warehousePath = createTemporaryDirectory().getAbsolutePath(); | ||
processor = new PutIceberg(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
catalog.dropTable(TABLE_IDENTIFIER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.