Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion flowvault/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,6 @@ Sample response:

Accessors: `queryResponse.getRecords()` (one read-only `Map<String, Object>` per row, in the vault's column order), `getMetadata().getColumns()`, `getRequestId()`. The vault returns at most 25 rows per call; page with `LIMIT` and `OFFSET` in the query (the SDK logs a warning when a call returns a full page).

> **Deprecation notice:** `getFields()` (the same rows under a misleading name) and `getErrors()` (always `null`) are deprecated. Use `getRecords()`, and catch `SkyflowException` for query failures.

# Get Tokens

Expand Down
Binary file modified flowvault/api-report/skyflow-flowvault-java.baseline.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion flowvault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<artifactId>skyflow-flowvault-java</artifactId>
<version>1.4.0</version>
<version>1.4.0-dev.329480b8</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Skyflow FlowVault SDK for the Java programming language</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ public static void main(String[] args) {
.query("SELECT * FROM <YOUR_TABLE_NAME> LIMIT 25 OFFSET 0")
.build();

// Optional: attach a request id of your own so the call can be traced end to end
QueryOptions options = QueryOptions.builder()
.interceptor(ctx -> {
ctx.addHeader(CustomHeaderKey.REQUEST_ID_HEADER, "QueryOptions"); // pass the request id here
})
.interceptor(ctx -> ctx.addHeader(CustomHeaderKey.REQUEST_ID_HEADER, "<YOUR_REQUEST_ID>"))
.build();
QueryResponse response = skyflowClient.vault().query(request, options);

// Step 5: Read the rows. Each map holds one record's column/value pairs.
// Step 5: Read the result. getRecords() holds one read-only map per row, keyed by column
// name in the order the vault returned them; getMetadata().getColumns() lists those names.
System.out.println("columns: " + response.getMetadata().getColumns());
for (Map<String, Object> row : response.getRecords()) {
System.out.println("row: " + row);
Object skyflowId = row.get("skyflowID"); // the system id column, when selected
System.out.println("skyflowID: " + skyflowId);
}
System.out.println("rows returned: " + response.getRecords().size());
System.out.println("requestId: " + response.getRequestId());
} catch (SkyflowException e) {
// Step 6: Handle any errors that occur during the process
Expand Down
41 changes: 12 additions & 29 deletions flowvault/src/main/java/com/skyflow/vault/data/QueryResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* Rows returned by a query. Values may be masked, but are never tokens or file URLs. Query has no
* per-record status: any failure is thrown as a SkyflowException.
* <p>
* This is the flowvault query response and stands on its own: it does not extend the shared
* {@code BaseQueryResponse}, whose {@code getFields()} / {@code getErrors()} shape belongs to the
* skyvault SDK and was never part of the flowvault contract.
*/
public class QueryResponse extends BaseQueryResponse {
public class QueryResponse {
private final List<Map<String, Object>> records;
private final QueryResponseMetadata metadata;
private final String requestId;

public QueryResponse(ArrayList<HashMap<String, Object>> fields, QueryResponseMetadata metadata, String requestId) {
super(fields);
public QueryResponse(List<? extends Map<String, Object>> records, QueryResponseMetadata metadata, String requestId) {
this.records = records == null
? Collections.<Map<String, Object>>emptyList()
: Collections.unmodifiableList(new ArrayList<Map<String, Object>>(records));
this.metadata = metadata;
this.requestId = requestId;
}
Expand All @@ -29,30 +35,7 @@ public QueryResponse(ArrayList<HashMap<String, Object>> fields, QueryResponseMet
* {@code LIMIT} and {@code OFFSET} in the query.
*/
public List<Map<String, Object>> getRecords() {
List<HashMap<String, Object>> rows = super.getFields();
return rows == null ? Collections.<Map<String, Object>>emptyList() : Collections.<Map<String, Object>>unmodifiableList(rows);
}

/**
* The rows the query returned.
*
* @deprecated The name is misleading: these are rows, not fields. Use {@link #getRecords()}.
*/
@Deprecated
@Override
public ArrayList<HashMap<String, Object>> getFields() {
return super.getFields();
}

/**
* Always null: query has no per-record errors, and any failure is thrown.
*
* @deprecated Carries no information. Catch SkyflowException for query failures instead.
*/
@Deprecated
@Override
public ArrayList<HashMap<String, Object>> getErrors() {
return super.getErrors();
return records;
}

public QueryResponseMetadata getMetadata() {
Expand All @@ -67,7 +50,7 @@ public String getRequestId() {
@Override
public String toString() {
Map<String, Object> view = new LinkedHashMap<>();
view.put("records", getRecords());
view.put("records", records);
view.put("metadata", metadata);
view.put("requestId", requestId);
return new GsonBuilder().serializeNulls().create().toJson(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,14 +949,14 @@ public void testQuery_wireResponseRowsReachCallerInOrder() throws Exception {

QueryResponse response = Utils.formatQueryResponse(wire, new HashMap<>());

Assert.assertEquals(2, response.getFields().size());
Assert.assertEquals(2, response.getRecords().size());
Assert.assertEquals(Arrays.asList("skyflow_id", "name", "age"),
new ArrayList<>(response.getFields().get(0).keySet()));
Assert.assertEquals(NON_ASCII_NAME, response.getFields().get(0).get("name"));
Assert.assertEquals(30, response.getFields().get(0).get("age"));
Assert.assertEquals("sky-2", response.getFields().get(1).get("skyflow_id"));
Assert.assertTrue(response.getFields().get(1).containsKey("age"));
Assert.assertNull(response.getFields().get(1).get("age"));
new ArrayList<>(response.getRecords().get(0).keySet()));
Assert.assertEquals(NON_ASCII_NAME, response.getRecords().get(0).get("name"));
Assert.assertEquals(30, response.getRecords().get(0).get("age"));
Assert.assertEquals("sky-2", response.getRecords().get(1).get("skyflow_id"));
Assert.assertTrue(response.getRecords().get(1).containsKey("age"));
Assert.assertNull(response.getRecords().get(1).get("age"));
Assert.assertEquals(Arrays.asList("skyflow_id", "name", "age"), response.getMetadata().getColumns());
}

Expand Down
18 changes: 8 additions & 10 deletions flowvault/src/test/java/com/skyflow/utils/UtilsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,9 @@ public void testFormatQueryResponse_rowsMetadataAndRequestId() {

QueryResponse formatted = Utils.formatQueryResponse(response, headers);

Assert.assertEquals(2, formatted.getFields().size());
Assert.assertEquals(row1, formatted.getFields().get(0));
Assert.assertEquals(row2, formatted.getFields().get(1));
Assert.assertNull(formatted.getErrors());
Assert.assertEquals(2, formatted.getRecords().size());
Assert.assertEquals(row1, formatted.getRecords().get(0));
Assert.assertEquals(row2, formatted.getRecords().get(1));
Assert.assertEquals(Arrays.asList("skyflow_id", "name"), formatted.getMetadata().getColumns());
// call-level: set even though nothing failed
Assert.assertEquals("req-query-1", formatted.getRequestId());
Expand All @@ -760,7 +759,7 @@ public void testFormatQueryResponse_preservesColumnOrderOfEachRow() {
QueryResponse formatted = Utils.formatQueryResponse(response, new HashMap<>());

Assert.assertEquals(Arrays.asList("zeta", "alpha", "mid"),
new ArrayList<>(formatted.getFields().get(0).keySet()));
new ArrayList<>(formatted.getRecords().get(0).keySet()));
}

@Test
Expand All @@ -771,16 +770,15 @@ public void testFormatQueryResponse_recordWithoutDataBecomesEmptyRow() {

QueryResponse formatted = Utils.formatQueryResponse(response, new HashMap<>());

Assert.assertEquals(1, formatted.getFields().size());
Assert.assertTrue(formatted.getFields().get(0).isEmpty());
Assert.assertEquals(1, formatted.getRecords().size());
Assert.assertTrue(formatted.getRecords().get(0).isEmpty());
}

@Test
public void testFormatQueryResponse_nullResponseReturnsEmptyFieldsAndNonNullMetadata() {
QueryResponse formatted = Utils.formatQueryResponse(null, null);

Assert.assertTrue(formatted.getFields().isEmpty());
Assert.assertNull(formatted.getErrors());
Assert.assertTrue(formatted.getRecords().isEmpty());
Assert.assertNotNull(formatted.getMetadata());
Assert.assertNull(formatted.getMetadata().getColumns());
Assert.assertNull(formatted.getRequestId());
Expand All @@ -794,7 +792,7 @@ public void testFormatQueryResponse_metadataWithoutColumns() {

QueryResponse formatted = Utils.formatQueryResponse(response, new HashMap<>());

Assert.assertTrue(formatted.getFields().isEmpty());
Assert.assertTrue(formatted.getRecords().isEmpty());
Assert.assertNull(formatted.getMetadata().getColumns());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,8 @@ public void testQuery_success() throws Exception {

QueryResponse response = controller.query(request);
Assert.assertNotNull(INVALID_EXCEPTION_THROWN, response);
Assert.assertEquals(1, response.getFields().size());
Assert.assertEquals("sky-1", response.getFields().get(0).get("skyflow_id"));
Assert.assertNull(response.getErrors());
Assert.assertEquals(1, response.getRecords().size());
Assert.assertEquals("sky-1", response.getRecords().get(0).get("skyflow_id"));
Assert.assertEquals(Arrays.asList("skyflow_id", "name"), response.getMetadata().getColumns());
Assert.assertEquals("req-test-123", response.getRequestId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ public void testQueryResponse_gettersReturnConstructorValues() {
Assert.assertEquals(fields, response.getRecords());
Assert.assertSame(metadata, response.getMetadata());
Assert.assertEquals("req-1", response.getRequestId());
Assert.assertTrue(response instanceof BaseQueryResponse);
// flowvault's query response stands alone; the skyvault-shaped base is not part of its API
Assert.assertEquals(Object.class, QueryResponse.class.getSuperclass());
Assert.assertFalse(BaseQueryResponse.class.isAssignableFrom(QueryResponse.class));
}

@Test
Expand All @@ -379,8 +381,7 @@ public void testQueryResponse_toStringSerializesAllFieldsIncludingNulls() {
}

@Test
@SuppressWarnings("deprecation")
public void testQueryResponse_recordsAreReadOnlyAndDeprecatedGettersStillWork() {
public void testQueryResponse_recordsAreReadOnlyAndDetachedFromTheInputList() {
HashMap<String, Object> row = new HashMap<>();
row.put("name", "john");
ArrayList<HashMap<String, Object>> fields = new ArrayList<>(Collections.singletonList(row));
Expand All @@ -392,9 +393,9 @@ public void testQueryResponse_recordsAreReadOnlyAndDeprecatedGettersStillWork()
} catch (UnsupportedOperationException expected) {
Assert.assertEquals(1, response.getRecords().size());
}
// kept for compatibility until removal
Assert.assertSame(fields, response.getFields());
Assert.assertNull(response.getErrors());
// the response copies the rows, so later changes to the caller's list do not leak in
fields.clear();
Assert.assertEquals(1, response.getRecords().size());
// a null row list reads as empty, never null
Assert.assertTrue(new QueryResponse(null, null, null).getRecords().isEmpty());
}
Expand Down
Loading