Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

import java.util.Objects;


/**
* Represents an array data type in the Coral type system.
*/
public final class CoralArrayType implements CoralDataType {
private final CoralDataType elementType;
private final boolean nullable;

/**
* Creates a new array type.
* @param elementType the type of elements in the array
* @param nullable whether this type allows null values
*/
public CoralArrayType(CoralDataType elementType, boolean nullable) {
this.elementType = Objects.requireNonNull(elementType, "Element type cannot be null");
this.nullable = nullable;
}

/**
* Returns the type of elements in this array.
* @return the element type
*/
public CoralDataType getElementType() {
return elementType;
}

@Override
public CoralTypeKind getKind() {
return CoralTypeKind.ARRAY;
}

@Override
public boolean isNullable() {
return nullable;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
CoralArrayType that = (CoralArrayType) o;
return nullable == that.nullable && Objects.equals(elementType, that.elementType);
}

@Override
public int hashCode() {
return Objects.hash(elementType, nullable);
}

@Override
public String toString() {
return "ARRAY<" + elementType + ">" + (nullable ? " NULL" : " NOT NULL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

import java.util.Objects;


/**
* Represents a fixed-length character data type in the Coral type system.
*/
public final class CoralCharType implements CoralDataType {
private final int length;
private final boolean nullable;

/**
* Creates a new CHAR type.
* @param length the fixed length of the character string
* @param nullable whether this type allows null values
*/
public CoralCharType(int length, boolean nullable) {
if (length <= 0) {
throw new IllegalArgumentException("Length must be positive, got: " + length);
}
this.length = length;
this.nullable = nullable;
}

/**
* Returns the fixed length of this CHAR type.
* @return the length
*/
public int getLength() {
return length;
}

@Override
public CoralTypeKind getKind() {
return CoralTypeKind.CHAR;
}

@Override
public boolean isNullable() {
return nullable;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
CoralCharType that = (CoralCharType) o;
return length == that.length && nullable == that.nullable;
}

@Override
public int hashCode() {
return Objects.hash(length, nullable);
}

@Override
public String toString() {
return "CHAR(" + length + ")" + (nullable ? " NULL" : " NOT NULL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

/**
* Represents a data type in the Coral type system.
* This interface provides a planner-agnostic abstraction for data types
* that can be converted to various execution engine specific types.
*/
public interface CoralDataType {
/**
* Returns the kind of this data type.
* @return the type kind
*/
CoralTypeKind getKind();

/**
* Returns whether this data type allows null values.
* @return true if nullable, false otherwise
*/
boolean isNullable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

import java.util.Objects;


/**
* Represents a decimal data type with precision and scale in the Coral type system.
*/
public final class CoralDecimalType implements CoralDataType {
private final int precision;
private final int scale;
private final boolean nullable;

/**
* Creates a new decimal type.
* @param precision the total number of digits
* @param scale the number of digits after the decimal point
* @param nullable whether this type allows null values
*/
public CoralDecimalType(int precision, int scale, boolean nullable) {
if (precision <= 0) {
throw new IllegalArgumentException("Precision must be positive, got: " + precision);
}
if (scale < 0 || scale > precision) {
throw new IllegalArgumentException(
"Scale must be non-negative and <= precision, got scale=" + scale + ", precision=" + precision);
}
this.precision = precision;
this.scale = scale;
this.nullable = nullable;
}

/**
* Returns the precision (total number of digits).
* @return the precision
*/
public int getPrecision() {
return precision;
}

/**
* Returns the scale (number of digits after decimal point).
* @return the scale
*/
public int getScale() {
return scale;
}

@Override
public CoralTypeKind getKind() {
return CoralTypeKind.DECIMAL;
}

@Override
public boolean isNullable() {
return nullable;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
CoralDecimalType that = (CoralDecimalType) o;
return precision == that.precision && scale == that.scale && nullable == that.nullable;
}

@Override
public int hashCode() {
return Objects.hash(precision, scale, nullable);
}

@Override
public String toString() {
return "DECIMAL(" + precision + "," + scale + ")" + (nullable ? " NULL" : " NOT NULL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

import java.util.Objects;


/**
* Represents a map data type in the Coral type system.
*/
public final class CoralMapType implements CoralDataType {
private final CoralDataType keyType;
private final CoralDataType valueType;
private final boolean nullable;

/**
* Creates a new map type.
* @param keyType the type of keys in the map
* @param valueType the type of values in the map
* @param nullable whether this type allows null values
*/
public CoralMapType(CoralDataType keyType, CoralDataType valueType, boolean nullable) {
this.keyType = Objects.requireNonNull(keyType, "Key type cannot be null");
this.valueType = Objects.requireNonNull(valueType, "Value type cannot be null");
this.nullable = nullable;
}

/**
* Returns the type of keys in this map.
* @return the key type
*/
public CoralDataType getKeyType() {
return keyType;
}

/**
* Returns the type of values in this map.
* @return the value type
*/
public CoralDataType getValueType() {
return valueType;
}

@Override
public CoralTypeKind getKind() {
return CoralTypeKind.MAP;
}

@Override
public boolean isNullable() {
return nullable;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
CoralMapType that = (CoralMapType) o;
return nullable == that.nullable && Objects.equals(keyType, that.keyType)
&& Objects.equals(valueType, that.valueType);
}

@Override
public int hashCode() {
return Objects.hash(keyType, valueType, nullable);
}

@Override
public String toString() {
return "MAP<" + keyType + "," + valueType + ">" + (nullable ? " NULL" : " NOT NULL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common.types;

import java.util.Objects;


/**
* Represents a primitive data type in the Coral type system.
* This includes basic types like BOOLEAN, INT, DOUBLE, STRING, etc.
*/
public final class CoralPrimitiveType implements CoralDataType {
private final CoralTypeKind kind;
private final boolean nullable;

/**
* Creates a new primitive type.
* @param kind the type kind (must be a primitive type)
* @param nullable whether this type allows null values
*/
public CoralPrimitiveType(CoralTypeKind kind, boolean nullable) {
this.kind = Objects.requireNonNull(kind, "Type kind cannot be null");
this.nullable = nullable;
}

@Override
public CoralTypeKind getKind() {
return kind;
}

@Override
public boolean isNullable() {
return nullable;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
CoralPrimitiveType that = (CoralPrimitiveType) o;
return nullable == that.nullable && kind == that.kind;
}

@Override
public int hashCode() {
return Objects.hash(kind, nullable);
}

@Override
public String toString() {
return kind.name() + (nullable ? " NULL" : " NOT NULL");
}
}
Loading