Skip to content

Commit 06b7386

Browse files
committed
Add type files
1 parent 5f52a39 commit 06b7386

File tree

9 files changed

+667
-0
lines changed

9 files changed

+667
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
3+
* Licensed under the BSD-2 Clause license.
4+
* See LICENSE in the project root for license information.
5+
*/
6+
package com.linkedin.coral.common.types;
7+
8+
import java.util.Objects;
9+
10+
11+
/**
12+
* Represents an array data type in the Coral type system.
13+
*/
14+
public final class ArrayType implements CoralDataType {
15+
private final CoralDataType elementType;
16+
private final boolean nullable;
17+
18+
/**
19+
* Creates a new array type.
20+
* @param elementType the type of elements in the array
21+
* @param nullable whether this type allows null values
22+
*/
23+
public static ArrayType of(CoralDataType elementType, boolean nullable) {
24+
return new ArrayType(elementType, nullable);
25+
}
26+
27+
private ArrayType(CoralDataType elementType, boolean nullable) {
28+
this.elementType = Objects.requireNonNull(elementType, "Element type cannot be null");
29+
this.nullable = nullable;
30+
}
31+
32+
/**
33+
* Returns the type of elements in this array.
34+
* @return the element type
35+
*/
36+
public CoralDataType getElementType() {
37+
return elementType;
38+
}
39+
40+
@Override
41+
public CoralTypeKind getKind() {
42+
return CoralTypeKind.ARRAY;
43+
}
44+
45+
@Override
46+
public boolean isNullable() {
47+
return nullable;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o)
53+
return true;
54+
if (o == null || getClass() != o.getClass())
55+
return false;
56+
ArrayType that = (ArrayType) o;
57+
return nullable == that.nullable && Objects.equals(elementType, that.elementType);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(elementType, nullable);
63+
}
64+
65+
@Override
66+
public String toString() {
67+
return "ARRAY<" + elementType + ">" + (nullable ? " NULL" : " NOT NULL");
68+
}
69+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
3+
* Licensed under the BSD-2 Clause license.
4+
* See LICENSE in the project root for license information.
5+
*/
6+
package com.linkedin.coral.common.types;
7+
8+
import java.util.Objects;
9+
10+
11+
/**
12+
* Represents a fixed-length character data type in the Coral type system.
13+
*/
14+
public final class CharType implements CoralDataType {
15+
private final int length;
16+
private final boolean nullable;
17+
18+
/**
19+
* Creates a new CHAR type.
20+
* @param length the fixed length of the character string
21+
* @param nullable whether this type allows null values
22+
*/
23+
public static CharType of(int length, boolean nullable) {
24+
if (length <= 0) {
25+
throw new IllegalArgumentException("Length must be positive, got: " + length);
26+
}
27+
return new CharType(length, nullable);
28+
}
29+
30+
private CharType(int length, boolean nullable) {
31+
this.length = length;
32+
this.nullable = nullable;
33+
}
34+
35+
/**
36+
* Returns the fixed length of this CHAR type.
37+
* @return the length
38+
*/
39+
public int getLength() {
40+
return length;
41+
}
42+
43+
@Override
44+
public CoralTypeKind getKind() {
45+
return CoralTypeKind.CHAR;
46+
}
47+
48+
@Override
49+
public boolean isNullable() {
50+
return nullable;
51+
}
52+
53+
@Override
54+
public boolean equals(Object o) {
55+
if (this == o)
56+
return true;
57+
if (o == null || getClass() != o.getClass())
58+
return false;
59+
CharType that = (CharType) o;
60+
return length == that.length && nullable == that.nullable;
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Objects.hash(length, nullable);
66+
}
67+
68+
@Override
69+
public String toString() {
70+
return "CHAR(" + length + ")" + (nullable ? " NULL" : " NOT NULL");
71+
}
72+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
3+
* Licensed under the BSD-2 Clause license.
4+
* See LICENSE in the project root for license information.
5+
*/
6+
package com.linkedin.coral.common.types;
7+
8+
import java.util.Objects;
9+
10+
11+
/**
12+
* Represents a decimal data type with precision and scale in the Coral type system.
13+
*/
14+
public final class DecimalType implements CoralDataType {
15+
private final int precision;
16+
private final int scale;
17+
private final boolean nullable;
18+
19+
/**
20+
* Creates a new decimal type.
21+
* @param precision the total number of digits
22+
* @param scale the number of digits after the decimal point
23+
* @param nullable whether this type allows null values
24+
*/
25+
public static DecimalType of(int precision, int scale, boolean nullable) {
26+
if (precision <= 0) {
27+
throw new IllegalArgumentException("Precision must be positive, got: " + precision);
28+
}
29+
if (scale < 0 || scale > precision) {
30+
throw new IllegalArgumentException(
31+
"Scale must be non-negative and <= precision, got scale=" + scale + ", precision=" + precision);
32+
}
33+
return new DecimalType(precision, scale, nullable);
34+
}
35+
36+
private DecimalType(int precision, int scale, boolean nullable) {
37+
this.precision = precision;
38+
this.scale = scale;
39+
this.nullable = nullable;
40+
}
41+
42+
/**
43+
* Returns the precision (total number of digits).
44+
* @return the precision
45+
*/
46+
public int getPrecision() {
47+
return precision;
48+
}
49+
50+
/**
51+
* Returns the scale (number of digits after decimal point).
52+
* @return the scale
53+
*/
54+
public int getScale() {
55+
return scale;
56+
}
57+
58+
@Override
59+
public CoralTypeKind getKind() {
60+
return CoralTypeKind.DECIMAL;
61+
}
62+
63+
@Override
64+
public boolean isNullable() {
65+
return nullable;
66+
}
67+
68+
@Override
69+
public boolean equals(Object o) {
70+
if (this == o)
71+
return true;
72+
if (o == null || getClass() != o.getClass())
73+
return false;
74+
DecimalType that = (DecimalType) o;
75+
return precision == that.precision && scale == that.scale && nullable == that.nullable;
76+
}
77+
78+
@Override
79+
public int hashCode() {
80+
return Objects.hash(precision, scale, nullable);
81+
}
82+
83+
@Override
84+
public String toString() {
85+
return "DECIMAL(" + precision + "," + scale + ")" + (nullable ? " NULL" : " NOT NULL");
86+
}
87+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
3+
* Licensed under the BSD-2 Clause license.
4+
* See LICENSE in the project root for license information.
5+
*/
6+
package com.linkedin.coral.common.types;
7+
8+
import java.util.Objects;
9+
10+
11+
/**
12+
* Represents a map data type in the Coral type system.
13+
*/
14+
public final class MapType implements CoralDataType {
15+
private final CoralDataType keyType;
16+
private final CoralDataType valueType;
17+
private final boolean nullable;
18+
19+
/**
20+
* Creates a new map type.
21+
* @param keyType the type of keys in the map
22+
* @param valueType the type of values in the map
23+
* @param nullable whether this type allows null values
24+
*/
25+
public static MapType of(CoralDataType keyType, CoralDataType valueType, boolean nullable) {
26+
return new MapType(keyType, valueType, nullable);
27+
}
28+
29+
private MapType(CoralDataType keyType, CoralDataType valueType, boolean nullable) {
30+
this.keyType = Objects.requireNonNull(keyType, "Key type cannot be null");
31+
this.valueType = Objects.requireNonNull(valueType, "Value type cannot be null");
32+
this.nullable = nullable;
33+
}
34+
35+
/**
36+
* Returns the type of keys in this map.
37+
* @return the key type
38+
*/
39+
public CoralDataType getKeyType() {
40+
return keyType;
41+
}
42+
43+
/**
44+
* Returns the type of values in this map.
45+
* @return the value type
46+
*/
47+
public CoralDataType getValueType() {
48+
return valueType;
49+
}
50+
51+
@Override
52+
public CoralTypeKind getKind() {
53+
return CoralTypeKind.MAP;
54+
}
55+
56+
@Override
57+
public boolean isNullable() {
58+
return nullable;
59+
}
60+
61+
@Override
62+
public boolean equals(Object o) {
63+
if (this == o)
64+
return true;
65+
if (o == null || getClass() != o.getClass())
66+
return false;
67+
MapType that = (MapType) o;
68+
return nullable == that.nullable && Objects.equals(keyType, that.keyType)
69+
&& Objects.equals(valueType, that.valueType);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
return Objects.hash(keyType, valueType, nullable);
75+
}
76+
77+
@Override
78+
public String toString() {
79+
return "MAP<" + keyType + "," + valueType + ">" + (nullable ? " NULL" : " NOT NULL");
80+
}
81+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2024-2025 LinkedIn Corporation. All rights reserved.
3+
* Licensed under the BSD-2 Clause license.
4+
* See LICENSE in the project root for license information.
5+
*/
6+
package com.linkedin.coral.common.types;
7+
8+
import java.util.Objects;
9+
10+
11+
/**
12+
* Represents a primitive data type in the Coral type system.
13+
* This includes basic types like BOOLEAN, INT, DOUBLE, STRING, etc.
14+
*/
15+
public final class PrimitiveType implements CoralDataType {
16+
private final CoralTypeKind kind;
17+
private final boolean nullable;
18+
19+
/**
20+
* Creates a new primitive type.
21+
* @param kind the type kind (must be a primitive type)
22+
* @param nullable whether this type allows null values
23+
*/
24+
public static PrimitiveType of(CoralTypeKind kind, boolean nullable) {
25+
return new PrimitiveType(kind, nullable);
26+
}
27+
28+
private PrimitiveType(CoralTypeKind kind, boolean nullable) {
29+
this.kind = Objects.requireNonNull(kind, "Type kind cannot be null");
30+
this.nullable = nullable;
31+
}
32+
33+
@Override
34+
public CoralTypeKind getKind() {
35+
return kind;
36+
}
37+
38+
@Override
39+
public boolean isNullable() {
40+
return nullable;
41+
}
42+
43+
@Override
44+
public boolean equals(Object o) {
45+
if (this == o)
46+
return true;
47+
if (o == null || getClass() != o.getClass())
48+
return false;
49+
PrimitiveType that = (PrimitiveType) o;
50+
return nullable == that.nullable && kind == that.kind;
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(kind, nullable);
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return kind.name() + (nullable ? " NULL" : " NOT NULL");
61+
}
62+
}

0 commit comments

Comments
 (0)