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

refactor: make utility classes UnboxTransform and ToChunkTypeTransform public #6338

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Util/function/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {

dependencies {
api project(':qst-type')
api project(':engine-query-constants')
jcferretti marked this conversation as resolved.
Show resolved Hide resolved
api project(':engine-time')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this dependency on engine-time, given it is a bit more sprawling. Does ToChunkTypeTransform living in engine-time work for you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should work, yes


compileOnly libs.jetbrains.annotations

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.kafka;
package io.deephaven.function;

import io.deephaven.function.ToByteFunction;
import io.deephaven.function.ToLongFunction;
import io.deephaven.function.ToObjectFunction;
import io.deephaven.function.ToPrimitiveFunction;
import io.deephaven.function.TypedFunction;
import io.deephaven.qst.type.ArrayType;
import io.deephaven.qst.type.BoxedBooleanType;
import io.deephaven.qst.type.BoxedByteType;
Expand All @@ -28,15 +23,15 @@
import java.time.Instant;
import java.util.Objects;

import static io.deephaven.kafka.UnboxTransform.unboxByte;
import static io.deephaven.kafka.UnboxTransform.unboxChar;
import static io.deephaven.kafka.UnboxTransform.unboxDouble;
import static io.deephaven.kafka.UnboxTransform.unboxFloat;
import static io.deephaven.kafka.UnboxTransform.unboxInt;
import static io.deephaven.kafka.UnboxTransform.unboxLong;
import static io.deephaven.kafka.UnboxTransform.unboxShort;
import static io.deephaven.function.UnboxTransform.unboxByte;
import static io.deephaven.function.UnboxTransform.unboxChar;
import static io.deephaven.function.UnboxTransform.unboxDouble;
import static io.deephaven.function.UnboxTransform.unboxFloat;
import static io.deephaven.function.UnboxTransform.unboxInt;
import static io.deephaven.function.UnboxTransform.unboxLong;
import static io.deephaven.function.UnboxTransform.unboxShort;

class ToChunkTypeTransform {
public class ToChunkTypeTransform {

private static final ToByteFunction<Boolean> BOOLEAN_AS_BYTE = BooleanUtils::booleanAsByte;
private static final ToLongFunction<Instant> EPOCH_NANOS = DateTimeUtils::epochNanos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.kafka;

import io.deephaven.function.ToByteFunction;
import io.deephaven.function.ToCharFunction;
import io.deephaven.function.ToDoubleFunction;
import io.deephaven.function.ToFloatFunction;
import io.deephaven.function.ToIntFunction;
import io.deephaven.function.ToLongFunction;
import io.deephaven.function.ToObjectFunction;
import io.deephaven.function.ToPrimitiveFunction;
import io.deephaven.function.ToShortFunction;
import io.deephaven.function.TypedFunction;
package io.deephaven.function;

import io.deephaven.qst.type.ArrayType;
import io.deephaven.qst.type.BoxedBooleanType;
import io.deephaven.qst.type.BoxedByteType;
Expand All @@ -27,20 +17,21 @@
import io.deephaven.qst.type.GenericType;
import io.deephaven.qst.type.InstantType;
import io.deephaven.qst.type.StringType;
import io.deephaven.util.type.TypeUtils;

import java.util.Objects;
import java.util.Optional;

class UnboxTransform {
import static io.deephaven.util.QueryConstants.*;

public class UnboxTransform {

private static final ToByteFunction<Byte> UNBOX_BYTE = TypeUtils::unbox;
private static final ToCharFunction<Character> UNBOX_CHAR = TypeUtils::unbox;
private static final ToShortFunction<Short> UNBOX_SHORT = TypeUtils::unbox;
private static final ToIntFunction<Integer> UNBOX_INT = TypeUtils::unbox;
private static final ToLongFunction<Long> UNBOX_LONG = TypeUtils::unbox;
private static final ToFloatFunction<Float> UNBOX_FLOAT = TypeUtils::unbox;
private static final ToDoubleFunction<Double> UNBOX_DOULE = TypeUtils::unbox;
private static final ToDoubleFunction<Double> UNBOX_DOUBLE = TypeUtils::unbox;

/**
* Returns the Deephaven unboxed equivalent of {@code f}. Relevant for all {@link BoxedType boxed types} except the
Expand Down Expand Up @@ -161,7 +152,7 @@ public static <T> ToFloatFunction<T> unboxFloat(ToObjectFunction<T, Float> f) {
* @see TypeUtils#unbox(Double)
*/
public static <T> ToDoubleFunction<T> unboxDouble(ToObjectFunction<T, Double> f) {
return f.mapToDouble(UNBOX_DOULE);
return f.mapToDouble(UNBOX_DOUBLE);
}

private enum UnboxFunctionVisitor implements TypedFunction.Visitor<Object, ToPrimitiveFunction<Object>> {
Expand Down Expand Up @@ -264,4 +255,36 @@ public ToPrimitiveFunction<T> visit(BoxedDoubleType doubleType) {
return unboxDouble(f.cast(doubleType));
}
}

// TODO: Clean up dependencies to be able to use io.deephaven.util.type.TypeUtils.
private static class TypeUtils {
public static byte unbox(Byte value) {
return (value == null ? NULL_BYTE : value);
}

public static char unbox(Character value) {
return (value == null ? NULL_CHAR : value);
}

public static double unbox(Double value) {
return (value == null ? NULL_DOUBLE : value);
}

public static float unbox(Float value) {
return (value == null ? NULL_FLOAT : value);
}

public static int unbox(Integer value) {
return (value == null ? NULL_INT : value);
}

public static long unbox(Long value) {
return (value == null ? NULL_LONG : value);
}

public static short unbox(Short value) {
return (value == null ? NULL_SHORT : value);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import io.deephaven.api.ColumnName;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.function.ToObjectFunction;
import io.deephaven.function.ToPrimitiveFunction;
import io.deephaven.function.TypedFunction;
import io.deephaven.function.*;
import io.deephaven.kafka.KafkaTools.Consume;
import io.deephaven.kafka.KafkaTools.KeyOrValue;
import io.deephaven.kafka.KafkaTools.KeyOrValueIngestData;
Expand Down
Loading