diff --git a/solr/core/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java b/solr/core/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
index 35c9f9d0db8..3dd30cc0e9c 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/CalciteSolrDriver.java
@@ -30,7 +30,9 @@ import java.util.Properties;
*
It accepts connect strings that start with "jdbc:calcitesolr:".
*/
public class CalciteSolrDriver extends Driver {
- protected CalciteSolrDriver() {
+ public final static String CONNECT_STRING_PREFIX = "jdbc:calcitesolr:";
+
+ private CalciteSolrDriver() {
super();
}
@@ -38,11 +40,11 @@ public class CalciteSolrDriver extends Driver {
new CalciteSolrDriver().register();
}
+ @Override
protected String getConnectStringPrefix() {
- return "jdbc:calcitesolr:";
+ return CONNECT_STRING_PREFIX;
}
-
@Override
public Connection connect(String url, Properties info) throws SQLException {
Connection connection = super.connect(url, info);
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrAggregate.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrAggregate.java
index 582b9c4e167..aed2e339801 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrAggregate.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrAggregate.java
@@ -24,7 +24,7 @@ import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.sql.SqlAggFunction;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.util.ImmutableBitSet;
-import org.apache.solr.client.solrj.io.stream.metrics.*;
+import org.apache.calcite.util.Pair;
import java.util.*;
@@ -32,6 +32,15 @@ import java.util.*;
* Implementation of {@link org.apache.calcite.rel.core.Aggregate} relational expression in Solr.
*/
class SolrAggregate extends Aggregate implements SolrRel {
+ private static final List SUPPORTED_AGGREGATIONS = Arrays.asList(
+ SqlStdOperatorTable.COUNT,
+ SqlStdOperatorTable.SUM,
+ SqlStdOperatorTable.SUM0,
+ SqlStdOperatorTable.MIN,
+ SqlStdOperatorTable.MAX,
+ SqlStdOperatorTable.AVG
+ );
+
SolrAggregate(
RelOptCluster cluster,
RelTraitSet traitSet,
@@ -58,12 +67,12 @@ class SolrAggregate extends Aggregate implements SolrRel {
final List inNames = SolrRules.solrFieldNames(getInput().getRowType());
final List outNames = SolrRules.solrFieldNames(getRowType());
- List metrics = new ArrayList<>();
+ List> metrics = new ArrayList<>();
Map fieldMappings = new HashMap<>();
for(AggregateCall aggCall : aggCalls) {
- Metric metric = toSolrMetric(aggCall.getAggregation(), inNames, aggCall.getArgList());
+ Pair metric = toSolrMetric(aggCall.getAggregation(), inNames, aggCall.getArgList());
metrics.add(metric);
- fieldMappings.put(aggCall.getName(), metric.getIdentifier());
+ fieldMappings.put(aggCall.getName(), metric.getKey().toLowerCase(Locale.ROOT) + "(" + metric.getValue() + ")");
}
List buckets = new ArrayList<>();
@@ -78,22 +87,16 @@ class SolrAggregate extends Aggregate implements SolrRel {
implementor.addFieldMappings(fieldMappings);
}
- private Metric toSolrMetric(SqlAggFunction aggregation, List inNames, List args) {
+ private Pair toSolrMetric(SqlAggFunction aggregation, List inNames, List args) {
switch (args.size()) {
case 0:
- if(aggregation.equals(SqlStdOperatorTable.COUNT)) {
- return new CountMetric();
+ if (aggregation.equals(SqlStdOperatorTable.COUNT)) {
+ return new Pair<>(aggregation.getName(), "*");
}
case 1:
final String inName = inNames.get(args.get(0));
- if (aggregation.equals(SqlStdOperatorTable.SUM) || aggregation.equals(SqlStdOperatorTable.SUM0)) {
- return new SumMetric(inName);
- } else if (aggregation.equals(SqlStdOperatorTable.MIN)) {
- return new MinMetric(inName);
- } else if (aggregation.equals(SqlStdOperatorTable.MAX)) {
- return new MaxMetric(inName);
- } else if (aggregation.equals(SqlStdOperatorTable.AVG)) {
- return new MeanMetric(inName);
+ if(SUPPORTED_AGGREGATIONS.contains(aggregation)) {
+ return new Pair<>(aggregation.getName(), inName);
}
default:
throw new AssertionError("Invalid aggregation " + aggregation + " with args " + args + " with names" + inNames);
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrRel.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrRel.java
index 9a11488fc79..5b67627db73 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrRel.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrRel.java
@@ -19,7 +19,7 @@ package org.apache.solr.handler.sql;
import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.rel.RelNode;
-import org.apache.solr.client.solrj.io.stream.metrics.Metric;
+import org.apache.calcite.util.Pair;
import java.util.ArrayList;
import java.util.HashMap;
@@ -42,7 +42,7 @@ interface SolrRel extends RelNode {
String limitValue = null;
final List order = new ArrayList<>();
final List buckets = new ArrayList<>();
- final List metrics = new ArrayList<>();
+ final List> metricPairs = new ArrayList<>();
RelOptTable table;
SolrTable solrTable;
@@ -68,8 +68,8 @@ interface SolrRel extends RelNode {
this.buckets.addAll(buckets);
}
- void addMetrics(List metrics) {
- this.metrics.addAll(metrics);
+ void addMetrics(List> metrics) {
+ this.metricPairs.addAll(metrics);
}
void setLimit(String limit) {
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
index 167dc95a2e5..753e9f835ad 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java
@@ -27,13 +27,14 @@ import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTableQueryable;
+import org.apache.calcite.util.Pair;
import org.apache.solr.client.solrj.io.stream.CloudSolrStream;
import org.apache.solr.client.solrj.io.stream.RollupStream;
import org.apache.solr.client.solrj.io.stream.StatsStream;
import org.apache.solr.client.solrj.io.stream.TupleStream;
-import org.apache.solr.client.solrj.io.stream.metrics.Bucket;
-import org.apache.solr.client.solrj.io.stream.metrics.Metric;
+import org.apache.solr.client.solrj.io.stream.metrics.*;
import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.update.VersionInfo;
import java.io.IOException;
import java.util.*;
@@ -43,7 +44,7 @@ import java.util.*;
*/
class SolrTable extends AbstractQueryableTable implements TranslatableTable {
private static final String DEFAULT_QUERY = "*:*";
- private static final String DEFAULT_VERSION_FIELD = "_version_";
+ private static final String DEFAULT_VERSION_FIELD = VersionInfo.VERSION_FIELD;
private static final String DEFAULT_SCORE_FIELD = "score";
private final String collection;
@@ -81,7 +82,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {
*/
private Enumerable