Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: XPack FeatureSet functionality #35725

Merged
merged 20 commits into from Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e157257
Initial commit for XPack FeatureSet functionality
astefan Nov 12, 2018
2074166
Reverted wrong changes
astefan Nov 20, 2018
eb7bd5e
Introduce "client" parameter for REST requests
astefan Nov 20, 2018
22134d9
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 20, 2018
c65637d
Rest test case
astefan Nov 20, 2018
e0527cc
Addressed review comments
astefan Nov 22, 2018
ecda271
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 22, 2018
8730d9a
Moved FeatureSetUsage to x-pack core and addressed some of the comments.
astefan Nov 22, 2018
fa63073
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 22, 2018
402708c
Moved Metrics inside the PlanExecutor and addressed review comments
astefan Nov 22, 2018
caeb3f0
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 22, 2018
497cd87
Test fix
astefan Nov 22, 2018
4f31c3e
Polishing
astefan Nov 23, 2018
e81fff3
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 23, 2018
90e07c4
More polishing
astefan Nov 23, 2018
9bd7ee7
Cosmetic changes
astefan Nov 23, 2018
2dea767
Addressed feedback
astefan Nov 23, 2018
e56ce10
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 23, 2018
10ee84d
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 24, 2018
7b7c39f
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan Nov 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/reference/rest-api/info.asciidoc
Expand Up @@ -102,6 +102,11 @@ Example response:
"available" : true,
"enabled" : false
},
"sql" : {
"description" : "SQL access to Elasticsearch",
"available" : true,
"enabled" : true
},
"watcher" : {
"description" : "Alerting, Notification and Automation for the Elastic Stack",
"available" : true,
Expand Down
Expand Up @@ -159,6 +159,7 @@
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivilege;
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges;
import org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport;
import org.elasticsearch.xpack.core.sql.SqlFeatureSetUsage;
import org.elasticsearch.xpack.core.ssl.SSLService;
import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
Expand Down Expand Up @@ -387,6 +388,8 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
new NamedWriteableRegistry.Entry(RoleMapperExpression.class, AnyExpression.NAME, AnyExpression::new),
new NamedWriteableRegistry.Entry(RoleMapperExpression.class, FieldExpression.NAME, FieldExpression::new),
new NamedWriteableRegistry.Entry(RoleMapperExpression.class, ExceptExpression.NAME, ExceptExpression::new),
// sql
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.SQL, SqlFeatureSetUsage::new),
// watcher
new NamedWriteableRegistry.Entry(MetaData.Custom.class, WatcherMetaData.TYPE, WatcherMetaData::new),
new NamedWriteableRegistry.Entry(NamedDiff.class, WatcherMetaData.TYPE, WatcherMetaData::readDiffFrom),
Expand Down
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.sql;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.XPackFeatureSet;
import org.elasticsearch.xpack.core.XPackField;

import java.io.IOException;
import java.util.Map;

public class SqlFeatureSetUsage extends XPackFeatureSet.Usage {

private final Map<String, Object> stats;

public SqlFeatureSetUsage(StreamInput in) throws IOException {
super(in);
stats = in.readMap();
}

public SqlFeatureSetUsage(boolean available, boolean enabled, Map<String, Object> stats) {
super(XPackField.SQL, available, enabled);
this.stats = stats;
}

public Map<String, Object> stats() {
return stats;
}

@Override
protected void innerXContent(XContentBuilder builder, Params params) throws IOException {
super.innerXContent(builder, params);
if (enabled) {
for (Map.Entry<String, Object> entry : stats.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(stats);
}
}
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.xpack.sql.proto.Protocol;
import org.elasticsearch.xpack.sql.proto.SqlQueryRequest;
import org.elasticsearch.xpack.sql.proto.SqlQueryResponse;
import org.elasticsearch.xpack.sql.proto.RequestInfo;
import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;

import java.sql.SQLException;
Expand Down Expand Up @@ -51,9 +52,10 @@ public boolean ping(long timeoutInMs) throws SQLException {

public Cursor query(String sql, List<SqlTypedParamValue> params, RequestMeta meta) throws SQLException {
int fetch = meta.fetchSize() > 0 ? meta.fetchSize() : conCfg.pageSize();
SqlQueryRequest sqlRequest = new SqlQueryRequest(Mode.JDBC, sql, params, null,
Protocol.TIME_ZONE,
fetch, TimeValue.timeValueMillis(meta.timeoutInMs()), TimeValue.timeValueMillis(meta.queryTimeoutInMs()));
SqlQueryRequest sqlRequest = new SqlQueryRequest(sql, params, null, Protocol.TIME_ZONE,
fetch,
TimeValue.timeValueMillis(meta.timeoutInMs()), TimeValue.timeValueMillis(meta.queryTimeoutInMs()),
new RequestInfo(Mode.JDBC));
SqlQueryResponse response = httpClient.query(sqlRequest);
return new DefaultCursor(this, response.cursor(), toJdbcColumnInfo(response.columns()), response.rows(), meta);
}
Expand All @@ -63,8 +65,8 @@ public Cursor query(String sql, List<SqlTypedParamValue> params, RequestMeta met
* the scroll id to use to fetch the next page.
*/
public Tuple<String, List<List<Object>>> nextPage(String cursor, RequestMeta meta) throws SQLException {
SqlQueryRequest sqlRequest = new SqlQueryRequest(Mode.JDBC, cursor, TimeValue.timeValueMillis(meta.timeoutInMs()),
TimeValue.timeValueMillis(meta.queryTimeoutInMs()));
SqlQueryRequest sqlRequest = new SqlQueryRequest(cursor, TimeValue.timeValueMillis(meta.timeoutInMs()),
TimeValue.timeValueMillis(meta.queryTimeoutInMs()), new RequestInfo(Mode.JDBC));
SqlQueryResponse response = httpClient.query(sqlRequest);
return new Tuple<>(response.cursor(), response.rows());
}
Expand Down
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.sql.qa.single_node;

import org.elasticsearch.xpack.sql.qa.rest.RestSqlUsageTestCase;

public class RestSqlUsageIT extends RestSqlUsageTestCase {
}
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.sql.qa;

import java.util.Locale;

public enum FeatureMetric {
COMMAND,
GROUPBY,
HAVING,
JOIN,
LIMIT,
LOCAL,
ORDERBY,
SUBSELECT,
WHERE;

@Override
public String toString() {
return this.name().toLowerCase(Locale.ROOT);
}
}
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.sql.qa;

import java.util.Locale;

public enum QueryMetric {
JDBC, ODBC, CLI, CANVAS, REST;

public static QueryMetric fromString(String metric) {
if (metric == null || metric.equalsIgnoreCase("plain")) {
astefan marked this conversation as resolved.
Show resolved Hide resolved
return REST;
}
return QueryMetric.valueOf(metric.toUpperCase(Locale.ROOT));
astefan marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String toString() {
return this.name().toLowerCase(Locale.ROOT);
}
}