Skip to content

Commit d0f4232

Browse files
authored
[FSTORE-2025] add ordered primary key index config and fix error code for no featur… (#955)
* add ordered primary key index config and fix error code for no feature group found to handle new backend code of 400 instead of 404. * address copilot comment * revert error code change
1 parent 2f8dcf1 commit d0f4232

3 files changed

Lines changed: 105 additions & 2 deletions

File tree

java/hsfs/src/main/java/com/logicalclocks/hsfs/OnlineConfig.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
package com.logicalclocks.hsfs;
1919

20-
import lombok.AllArgsConstructor;
2120
import lombok.Getter;
2221
import lombok.NoArgsConstructor;
2322
import lombok.Setter;
2423

2524
import java.util.List;
2625

2726
@NoArgsConstructor
28-
@AllArgsConstructor
2927
public class OnlineConfig {
3028

3129
@Getter
@@ -35,4 +33,19 @@ public class OnlineConfig {
3533
@Getter
3634
@Setter
3735
private String tableSpace;
36+
37+
@Getter
38+
@Setter
39+
private PrimaryKeyIndexType primaryKeyIndexType;
40+
41+
public OnlineConfig(List<String> onlineComments, String tableSpace) {
42+
this.onlineComments = onlineComments;
43+
this.tableSpace = tableSpace;
44+
}
45+
46+
public OnlineConfig(List<String> onlineComments, String tableSpace, PrimaryKeyIndexType primaryKeyIndexType) {
47+
this.onlineComments = onlineComments;
48+
this.tableSpace = tableSpace;
49+
this.primaryKeyIndexType = primaryKeyIndexType;
50+
}
3851
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2026. Hopsworks AB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and limitations under the License.
15+
*
16+
*/
17+
18+
package com.logicalclocks.hsfs;
19+
20+
public enum PrimaryKeyIndexType {
21+
HASH,
22+
ORDERED
23+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2026. Hopsworks AB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and limitations under the License.
15+
*
16+
*/
17+
18+
package com.logicalclocks.hsfs;
19+
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
22+
import org.junit.Assert;
23+
import org.junit.jupiter.api.Test;
24+
25+
class TestOnlineConfig {
26+
27+
private final ObjectMapper objectMapper = new ObjectMapper();
28+
29+
@Test
30+
void testHashIndexTypeSerializedAndDeserialized() throws Exception {
31+
// Arrange
32+
OnlineConfig config = new OnlineConfig(null, null, PrimaryKeyIndexType.HASH);
33+
34+
// Act – round-trip through Jackson
35+
String json = objectMapper.writeValueAsString(config);
36+
OnlineConfig result = objectMapper.readValue(json, OnlineConfig.class);
37+
38+
// Assert
39+
Assert.assertEquals(PrimaryKeyIndexType.HASH, result.getPrimaryKeyIndexType());
40+
}
41+
42+
@Test
43+
void testOrderedIndexTypeSerializedAndDeserialized() throws Exception {
44+
// Arrange
45+
OnlineConfig config = new OnlineConfig(null, null, PrimaryKeyIndexType.ORDERED);
46+
47+
// Act
48+
String json = objectMapper.writeValueAsString(config);
49+
OnlineConfig result = objectMapper.readValue(json, OnlineConfig.class);
50+
51+
// Assert
52+
Assert.assertEquals(PrimaryKeyIndexType.ORDERED, result.getPrimaryKeyIndexType());
53+
}
54+
55+
@Test
56+
void testNoConfigPassedDefaultsToHash() throws Exception {
57+
// When no primaryKeyIndexType is set the server applies a TTL-driven default
58+
// and returns HASH for feature groups without TTL. Simulate that server response.
59+
String serverResponse = "{\"primaryKeyIndexType\":\"HASH\"}";
60+
61+
// Act
62+
OnlineConfig result = objectMapper.readValue(serverResponse, OnlineConfig.class);
63+
64+
// Assert
65+
Assert.assertEquals(PrimaryKeyIndexType.HASH, result.getPrimaryKeyIndexType());
66+
}
67+
}

0 commit comments

Comments
 (0)