malliaridis commented on code in PR #2479:
URL: https://github.com/apache/solr/pull/2479#discussion_r1840275323


##########
solr/core/src/java/org/apache/solr/cli/StreamTool.java:
##########
@@ -0,0 +1,507 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cli;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.PrintStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.solr.client.solrj.io.Lang;
+import org.apache.solr.client.solrj.io.SolrClientCache;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.comp.StreamComparator;
+import org.apache.solr.client.solrj.io.stream.PushBackStream;
+import org.apache.solr.client.solrj.io.stream.SolrStream;
+import org.apache.solr.client.solrj.io.stream.StreamContext;
+import org.apache.solr.client.solrj.io.stream.TupleStream;
+import org.apache.solr.client.solrj.io.stream.expr.Explanation;
+import org.apache.solr.client.solrj.io.stream.expr.Expressible;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParser;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.handler.CatStream;
+
+/** Supports stream command in the bin/solr script. */
+public class StreamTool extends ToolBase {
+
+  public StreamTool() {
+    this(CLIO.getOutStream());
+  }
+
+  public StreamTool(PrintStream stdout) {
+    super(stdout);
+  }
+
+  private final SolrClientCache solrClientCache = new SolrClientCache();
+
+  @Override
+  public String getName() {
+    return "stream";
+  }
+
+  private static final Option EXECUTION_OPTION =
+          Option.builder("e")
+                  .longOpt("execution")
+                  .hasArg()
+                  .argName("CONTEXT")
+                  .required(false)
+                  .desc(
+                          "Execution context is either 'local' (i.e CLI 
process) or 'solr'. Default is 'solr'")
+                  .build();
+
+  private static final Option COLLECTION_OPTION = Option.builder("c")
+            .longOpt("name")
+            .argName("NAME")
+            .hasArg()
+            .desc(
+                "Name of the collection to execute on if workers are 'solr'.  
Required for 'solr' worker.")
+            .build();
+
+  private static final Option FIELDS_OPTION = Option.builder("f")
+            .longOpt("fields")
+            .argName("FIELDS")
+            .hasArg()
+            .required(false)
+            .desc(
+                "The fields in the tuples to output. (defaults to fields in 
the first tuple of result set).")
+            .build();
+
+  private static final Option HEADER_OPTION =
+          Option.builder()
+                  .longOpt("header")
+                  .required(false)
+                  .desc("Whether or not to include a header line. 
(default=false)")
+                  .build();
+  private static final Option DELIMITER_OPTION = Option.builder()
+           .longOpt("delimiter")
+            .argName("CHARACTER")
+            .hasArg()
+            .required(false)
+            .desc("The output delimiter. (default=tab).")
+            .build();
+  private static final Option ARRAY_DELIMITER_OPTION = Option.builder()
+                .longOpt("array-delimiter")
+            .argName("CHARACTER")
+            .hasArg()
+            .required(false)
+            .desc("The delimiter multi-valued fields. (default=|)")
+            .build();
+
+  @Override
+  public Options getOptions() {
+    Options opts =
+            super.getOptions()
+                    .addOption(EXECUTION_OPTION)
+                    .addOption(COLLECTION_OPTION)
+                    .addOption(FIELDS_OPTION)
+                    .addOption(HEADER_OPTION)
+                    .addOption(DELIMITER_OPTION)
+                    .addOption(ARRAY_DELIMITER_OPTION)
+                    .addOption(CommonCLIOptions.CREDENTIALS_OPTION)
+                    .addOptionGroup(getConnectionOptions());
+
+    return opts;
+  }
+
+
+  @Override
+  @SuppressWarnings({"rawtypes"})
+  public void runImpl(CommandLine cli) throws Exception {
+
+    String expressionArgument = cli.getArgs()[0];
+    String execution = cli.getOptionValue(EXECUTION_OPTION,"solr");
+    String arrayDelimiter = cli.getOptionValue(ARRAY_DELIMITER_OPTION,"|");
+    String delimiter = cli.getOptionValue(DELIMITER_OPTION, "   ");
+    boolean includeHeaders = cli.hasOption(HEADER_OPTION);
+    String[] outputHeaders = getOutputFields(cli);
+
+    LineNumberReader bufferedReader = null;
+    String expr;
+    try {
+      Reader inputStream =
+          expressionArgument.toLowerCase(Locale.ROOT).endsWith("expr")
+              ? new InputStreamReader(
+                  new FileInputStream(expressionArgument), 
Charset.defaultCharset())

Review Comment:
   This change makes only sense if the file is supposed to have the file 
extension `.expr`. Not sure if there is a pattern we follow project-wide for 
custom file extensions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to