From 07c7b270186672af489f910bc09d3824fcf0caf7 Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Mon, 5 Dec 2022 14:15:23 +0100 Subject: Add tensor short form output option to vespa-get --- .../src/main/java/com/yahoo/vespaget/ClientParameters.java | 13 +++++++++++-- .../main/java/com/yahoo/vespaget/CommandLineOptions.java | 10 ++++++++++ .../src/main/java/com/yahoo/vespaget/DocumentRetriever.java | 2 +- .../src/main/java/com/yahoo/vespavisit/VdsVisit.java | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) (limited to 'vespaclient-java/src/main/java/com/yahoo') 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 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") -- cgit v1.2.3