aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-java
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-12-05 14:15:23 +0100
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-12-05 14:15:23 +0100
commit07c7b270186672af489f910bc09d3824fcf0caf7 (patch)
tree74201ced0b4ee93faa6011c07f7e0cc64bf96b8d /vespaclient-java
parent23e9f20ebc1b0d013bd3f95a9463a9fe92a2cb44 (diff)
Add tensor short form output option to vespa-get
Diffstat (limited to 'vespaclient-java')
-rw-r--r--vespaclient-java/src/main/java/com/yahoo/vespaget/ClientParameters.java13
-rw-r--r--vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java10
-rw-r--r--vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java2
-rw-r--r--vespaclient-java/src/main/java/com/yahoo/vespavisit/VdsVisit.java2
-rw-r--r--vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java3
-rw-r--r--vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java2
6 files changed, 27 insertions, 5 deletions
diff --git a/vespaclient-java/src/main/java/com/yahoo/vespaget/ClientParameters.java b/vespaclient-java/src/main/java/com/yahoo/vespaget/ClientParameters.java
index 6102f3da77f..7e464431f9a 100644
--- a/vespaclient-java/src/main/java/com/yahoo/vespaget/ClientParameters.java
+++ b/vespaclient-java/src/main/java/com/yahoo/vespaget/ClientParameters.java
@@ -37,13 +37,15 @@ public class ClientParameters {
public final DocumentProtocol.Priority priority;
// If full documents are printed, they will be printed as JSON (instead of XML)
public final boolean jsonOutput;
+ // Output JSON tensors in short form
+ public final boolean tensorShortForm;
private ClientParameters(
boolean help, Iterator<String> documentIds, boolean printIdsOnly,
String fieldSet, String route, String cluster, String configId,
boolean showDocSize, double timeout, boolean noRetry, int traceLevel,
- DocumentProtocol.Priority priority, boolean jsonOutput) {
+ DocumentProtocol.Priority priority, boolean jsonOutput, boolean tensorShortForm) {
this.help = help;
this.documentIds = documentIds;
@@ -58,6 +60,7 @@ public class ClientParameters {
this.traceLevel = traceLevel;
this.priority = priority;
this.jsonOutput = jsonOutput;
+ this.tensorShortForm = tensorShortForm;
}
public static class Builder {
@@ -74,6 +77,7 @@ public class ClientParameters {
private int traceLevel;
private DocumentProtocol.Priority priority;
private boolean jsonOutput;
+ private boolean tensorShortForm;
public Builder setHelp(boolean help) {
this.help = help;
@@ -140,10 +144,15 @@ public class ClientParameters {
return this;
}
+ public Builder setTensorShortForm(boolean tensorShortForm) {
+ this.tensorShortForm = tensorShortForm;
+ return this;
+ }
+
public ClientParameters build() {
return new ClientParameters(
help, documentIds, printIdsOnly, fieldSet, route, cluster, configId,
- showDocSize, timeout, noRetry, traceLevel, priority, jsonOutput);
+ showDocSize, timeout, noRetry, traceLevel, priority, jsonOutput, tensorShortForm);
}
}
diff --git a/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java b/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java
index b1bc9c76328..a6af51687eb 100644
--- a/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java
+++ b/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java
@@ -39,6 +39,7 @@ public class CommandLineOptions {
public static final String PRIORITY_OPTION = "priority";
public static final String JSONOUTPUT_OPTION = "jsonoutput";
public static final String XMLOUTPUT_OPTION = "xmloutput";
+ public static final String TENSOR_SHORT_FORM_OPTION = "tensor-short-form";
private final Options options = createOptions();
private final InputStream stdIn;
@@ -131,6 +132,13 @@ public class CommandLineOptions {
.desc("XML output")
.longOpt(XMLOUTPUT_OPTION).build());
+ // TODO Vespa 9: replace with --tensor-long-form ?
+ options.addOption(Option.builder()
+ .longOpt(TENSOR_SHORT_FORM_OPTION)
+ .desc("Output JSON tensors in short form. Will be the default on Vespa 9")
+ .hasArg(false)
+ .build());
+
return options;
}
@@ -159,6 +167,7 @@ public class CommandLineOptions {
boolean showDocSize = cl.hasOption(SHOWDOCSIZE_OPTION);
boolean jsonOutput = cl.hasOption(JSONOUTPUT_OPTION);
boolean xmlOutput = cl.hasOption(XMLOUTPUT_OPTION);
+ boolean tensorShortForm = cl.hasOption(TENSOR_SHORT_FORM_OPTION);
int trace = getTrace(cl);
DocumentProtocol.Priority priority = getPriority(cl);
double timeout = getTimeout(cl);
@@ -209,6 +218,7 @@ public class CommandLineOptions {
.setPriority(priority)
.setTimeout(timeout)
.setJsonOutput(!xmlOutput)
+ .setTensorShortForm(tensorShortForm)
.build();
} catch (ParseException pe) {
throw new IllegalArgumentException(pe.getMessage());
diff --git a/vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java b/vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java
index 91e3b5205c1..1a2f3424b3c 100644
--- a/vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java
+++ b/vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java
@@ -168,7 +168,7 @@ public class DocumentRetriever {
System.out.println(document.getId());
} else {
if (params.jsonOutput) {
- System.out.print(Utf8.toString(JsonWriter.toByteArray(document)));
+ System.out.print(Utf8.toString(JsonWriter.toByteArray(document, params.tensorShortForm)));
} else {
System.out.print(document.toXML(" "));
}
diff --git a/vespaclient-java/src/main/java/com/yahoo/vespavisit/VdsVisit.java b/vespaclient-java/src/main/java/com/yahoo/vespavisit/VdsVisit.java
index c022713cbb6..44e2cd55bdc 100644
--- a/vespaclient-java/src/main/java/com/yahoo/vespavisit/VdsVisit.java
+++ b/vespaclient-java/src/main/java/com/yahoo/vespavisit/VdsVisit.java
@@ -348,7 +348,7 @@ public class VdsVisit {
FixedBucketSpaces.defaultSpace(), FixedBucketSpaces.globalSpace(), FixedBucketSpaces.defaultSpace()))
.build());
- // TODO Vespa 9 replace with --tensor-long-form ?
+ // TODO Vespa 9: replace with --tensor-long-form ?
options.addOption(Option.builder()
.longOpt("tensor-short-form")
.desc("Output JSON tensors in short form. Will be the default on Vespa 9")
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java
index c448e5d55f5..9c1b16b8770 100644
--- a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java
+++ b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java
@@ -57,6 +57,7 @@ public class CommandLineOptionsTest {
assertFalse(params.noRetry);
assertEquals(0, params.traceLevel);
assertEquals(DocumentProtocol.Priority.NORMAL_2, params.priority);
+ assertFalse(params.tensorShortForm); // TODO Vespa 9: change default to true
}
@Test
@@ -70,6 +71,7 @@ public class CommandLineOptionsTest {
"--noretry",
"--trace", "1",
"--priority", Integer.toString(DocumentProtocol.Priority.HIGH_3.getValue()),
+ "--tensor-short-form",
"id:1", "id:2"
);
@@ -81,6 +83,7 @@ public class CommandLineOptionsTest {
assertTrue(params.noRetry);
assertEquals(1, params.traceLevel);
assertEquals(DocumentProtocol.Priority.HIGH_3, params.priority);
+ assertTrue(params.tensorShortForm);
Iterator<String> documentsIds = params.documentIds;
assertEquals("id:1", documentsIds.next());
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java b/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java
index 24e303d6fce..e6fe985acbf 100644
--- a/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java
+++ b/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java
@@ -240,7 +240,7 @@ public class DocumentRetrieverTest {
}
@Test
- void testEmtpyClusterList() throws DocumentRetrieverException {
+ void testEmptyClusterList() throws DocumentRetrieverException {
Throwable exception = assertThrows(DocumentRetrieverException.class, () -> {
ClientParameters params = createParameters()