-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to configure value schema using Avro
- Loading branch information
1 parent
19cbee2
commit d1f9ecf
Showing
25 changed files
with
1,388 additions
and
117 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
62 changes: 62 additions & 0 deletions
62
...file-pulse-api/src/main/java/io/streamthoughts/kafka/connect/filepulse/internal/Pair.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,62 @@ | ||
/* | ||
* Copyright 2023 StreamThoughts. | ||
* | ||
* 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 io.streamthoughts.kafka.connect.filepulse.internal; | ||
import java.util.Objects; | ||
|
||
public class Pair<K, V> { | ||
private final K key; | ||
private final V value; | ||
|
||
public Pair(K key, V value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public K getKey() { | ||
return key; | ||
} | ||
|
||
public V getValue() { | ||
return value; | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Pair<?, ?> pair = (Pair<?, ?>) o; | ||
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(key, value); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public String toString() { | ||
return "Pair{" | ||
+ "key=" + key | ||
+ ", value=" + value | ||
+ '}'; | ||
} | ||
} |
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
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
78 changes: 78 additions & 0 deletions
78
...mat/src/main/java/io/streamthoughts/kafka/connect/filepulse/avro/AvroSchemaConverter.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,78 @@ | ||
/* | ||
* Copyright 2023 StreamThoughts. | ||
* | ||
* 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 io.streamthoughts.kafka.connect.filepulse.avro; | ||
|
||
import io.streamthoughts.kafka.connect.filepulse.avro.internal.ConnectSchemaConverter; | ||
import io.streamthoughts.kafka.connect.filepulse.avro.internal.ConnectSchemaConverters; | ||
import io.streamthoughts.kafka.connect.filepulse.internal.StringUtils; | ||
import org.apache.kafka.connect.data.Schema; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Utilities for converting between Connect runtime data format and Avro. | ||
*/ | ||
public final class AvroSchemaConverter { | ||
|
||
private final Map<org.apache.avro.Schema, Schema> toConnectSchemaCache; | ||
|
||
/** | ||
* Creates a new {@link AvroSchemaConverter} instance. | ||
*/ | ||
public AvroSchemaConverter() { | ||
toConnectSchemaCache = new HashMap<>(); | ||
} | ||
|
||
/** | ||
* Convert the given {@link org.apache.avro.Schema} into connect one. | ||
* | ||
* @param schema the string avro schema to be converted. | ||
* @return {@link Schema}. | ||
*/ | ||
public Schema toConnectSchema(final String schema) { | ||
if (StringUtils.isBlank(schema)) { | ||
return null; | ||
} | ||
org.apache.avro.Schema.Parser parser = new org.apache.avro.Schema.Parser(); | ||
return toConnectSchema(parser.parse(schema)); | ||
} | ||
|
||
/** | ||
* Convert the given {@link org.apache.avro.Schema} into connect one. | ||
* | ||
* @param schema the avro schema to be converted. | ||
* @return {@link Schema}. | ||
*/ | ||
public Schema toConnectSchema(final org.apache.avro.Schema schema) { | ||
Schema cachedSchema = toConnectSchemaCache.get(schema); | ||
if (cachedSchema != null) { | ||
return cachedSchema; | ||
} | ||
|
||
ConnectSchemaConverter converter = ConnectSchemaConverters.forType(schema.getType()); | ||
org.apache.kafka.connect.data.Schema resultSchema = converter.toConnectSchema( | ||
schema, | ||
new ConnectSchemaConverter.Options().forceOptional(false), | ||
new ConnectSchemaConverter.CyclicContext() | ||
); | ||
toConnectSchemaCache.put(schema, resultSchema); | ||
return resultSchema; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/java/io/streamthoughts/kafka/connect/filepulse/avro/UnsupportedAvroTypeException.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,29 @@ | ||
/* | ||
* Copyright 2023 StreamThoughts. | ||
* | ||
* 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 io.streamthoughts.kafka.connect.filepulse.avro; | ||
|
||
import io.streamthoughts.kafka.connect.filepulse.errors.ConnectFilePulseException; | ||
|
||
public class UnsupportedAvroTypeException extends ConnectFilePulseException { | ||
|
||
public UnsupportedAvroTypeException(final String message) { | ||
super(message); | ||
} | ||
|
||
} |
Oops, something went wrong.