Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible de parse date type from avro schema #325

Open
Z21GELHA opened this issue Sep 16, 2024 · 1 comment
Open

Impossible de parse date type from avro schema #325

Z21GELHA opened this issue Sep 16, 2024 · 1 comment

Comments

@Z21GELHA
Copy link

Hello,

Currently in the KafkaSteps class, when we try to map a date like 2024-09-16, we encounter some troubles because of the avro type.

In fact, when we have a date, we have this kind of Avro schema:
{ "default": null, "name": "my_date", "type": [ "null", { "logicalType": "date", "type": "int" } ] }

But because, the type is considered as an UNION, the parseAvro method doesn't transform the value in an Integer.

What I suggest is to modify the method like this to cover this situation:

@Nullable
    private Object parseAvro(String value, Schema valueSchema) {
        return switch (valueSchema.getType()) {
            case INT -> {
                if("date".equals(valueSchema.getProp("logicalType"))) {
                    yield (int) LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE).toEpochDay();
                } else {
                    yield Integer.parseInt(value);
                }
            }
            case LONG -> Long.parseLong(value);
            case FLOAT -> Float.parseFloat(value);
            case DOUBLE -> Double.parseDouble(value);
            case BOOLEAN -> Boolean.parseBoolean(value);
            default -> value;
        };
    }
@laujacq
Copy link
Collaborator

laujacq commented Sep 17, 2024

Hello,

Thank you for bringing this up.

The behavior you’re describing with Avro’s logicalType for dates makes sense for it to be managed

However, in this case we also need to manage the other subtypes in order to be more inclusive, such as :
• time-millis
• time-micros
• timestamp-millis
• timestamp-micros
• decimal

However, given our current priorities and other ongoing tasks, we will need to schedule this for future work. We will keep you updated in this issue.

In the meantime, feel free to fork the project and contribute 👍 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants