All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.kafka.ingest.JsonNodeInstantFieldCopier Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.kafka.ingest;

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.databind.JsonNode;
import io.deephaven.chunk.*;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.time.DateTimeUtils;

import java.time.Instant;

public class JsonNodeInstantFieldCopier implements FieldCopier {
    private final JsonPointer fieldPointer;

    public JsonNodeInstantFieldCopier(final String fieldPointerStr) {
        this.fieldPointer = JsonPointer.compile(fieldPointerStr);
    }

    @Override
    public void copyField(
            final ObjectChunk inputChunk,
            final WritableChunk publisherChunk,
            final int sourceOffset,
            final int destOffset,
            final int length) {
        final WritableLongChunk output = publisherChunk.asWritableLongChunk();
        for (int ii = 0; ii < length; ++ii) {
            final JsonNode node = (JsonNode) inputChunk.get(ii + sourceOffset);
            final Instant instant = JsonNodeUtil.getInstant(node, fieldPointer, true, true);
            output.set(ii + destOffset, DateTimeUtils.epochNanos(instant));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy