GithubHelp home page GithubHelp logo

sql-jdbc's Introduction

NOTE: We have merged this repository into Open Distro for Elasticsearch SQL as of 7/9/20. Please visit here for latest updates on SQL JDBC. Thanks.

Open Distro for ElasticSearch - JDBC

This is the driver for JDBC connectivity to a cluster running with Open Distro for Elasticsearch SQL support.

Specifications

The driver is compatible with JDBC 4.2 specification and requires a minimum of Java 8.

Using the driver

The driver comes in the form of a single jar file. To use it, simply place it on the classpath of the Java application that needs to use it.

If using with JDBC compatible BI tools, refer to the tool documentation on configuring a new JDBC driver. Typically, all that's required is to make the tool aware of the location of the driver jar and then use it to setup database (i.e Elasticsearch) connections.

Connection URL and other settings

To setup a connection, the driver requires a JDBC connection URL. The connection URL is of the form:

    jdbc:elasticsearch://[scheme://][host][:port][/context-path]?[property-key=value]&[property-key2=value2]..&[property-keyN=valueN]
  • scheme

    Can be one of http or https. Default is http.

  • host

    Hostname or IP address of the target cluster. Default is localhost.

  • port

    Port number on which the cluster's REST interface is listening. Default value depends on the scheme selected. For http, the default is 9200. For https, the default is 443.

  • context-path

    The context path at which the cluster REST interface is rooted. Not needed if the REST interface is simply available on the '/' context path.

  • property key=value

    The query string portion of the connection URL can contain desired connection settings in the form of one or more property-key=value pairs. The possible configuration properties are provided in the table below. The property keys are case sensitive but values are not unless otherwise indicated.

    Note that JDBC provides multiple APIs for specifying connection properties of which specifying them in the connection URL is just one. When directly coding with the driver you can choose any of the other options (refer sample code below). If you are setting up a connection via a tool, it is likely the tool will allow you to specify the connection URL with just the scheme, host, port and context-path components) while the the connection properties are provided separately. For example, you may not wish to place the user and password in the connection URL. Check the tool you are using for such support.

    The configurable connection properties are:

    Property Key Description Accepted Value(s) Default value
    user Connection username. mandatory if auth property selects a authentication scheme that mandates a username value any string null
    password Connection password. mandatory if auth property selects a authentication scheme that mandates a password value any string null
    fetchSize Cursor page size positive integer value. Max value is limited by index.max_result_window Elasticsearch setting 0 (for non-paginated response)
    logOutput location where driver logs should be emitted a valid file path null (logs are disabled)
    logLevel severity level for which driver logs should be emitted in order from highest(least logging) to lowest(most logging): OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL OFF (logs are disabled)
    auth authentication mechanism to use NONE (no auth), BASIC (HTTP Basic), AWS_SIGV4 (AWS SIGV4) basic if username and/or password is specified, NONE otherwise
    awsCredentialsProvider The AWS credential provider to be used when authentication mechanism is AWS_SIGV4 (AWS SIGV4). If not set, the driver will use DefaultAWSCredentialsProviderChain to sign the request. Note that the driver renamed the namespaces of its dependencies, so the value has to be an instance of com.amazonaws.opendistro.elasticsearch.sql.jdbc.shadow.com.amazonaws.auth.AWSCredentialsProvider Instance of an AWSCredentialProvider DefaultAWSCredentialsProviderChain
    region if authentication type is aws_sigv4, then this is the region value to use when signing requests. Only needed if the driver can not determine the region for the host endpoint. The driver will detect the region if the host endpoint matches a known url pattern. a valid AWS region value e.g. us-east-1 null (auto-detected if possible from the host endpoint)
    requestCompression whether to indicate acceptance of compressed (gzip) responses when making server requests true or false false
    useSSL whether to establish the connection over SSL/TLS true or false false if scheme is http, true if scheme is https
    trustStoreLocation location of the SSL/TLS truststore to use file path or URL as appropriate to the type of truststore null
    trustStoreType type of the truststore valid truststore type recognized by available Java security providers JKS
    trustStorePassword password to access the Trust Store any string null
    keyStoreLocation location of the SSL/TLS keystore to use file path or URL as appropriate to the type of keystore null
    keyStoreType type of the keystore valid keystore type recognized by available Java security providers JKS
    keyStorePassword password to access the keystore any string null
    trustSelfSigned shortcut way to indicate that any self-signed certificate should be accepted. A truststore is not required to be configured. true or false false
    hostnameVerification indicate whether certificate hostname verification should be performed when using SSL/TLS true or false true

Connecting using the DriverManager interface

The main Driver class is com.amazon.opendistroforelasticsearch.jdbc.Driver. If the driver jar is on the application classpath, no other configuration is required.

Code samples to open a connection for some typical scenarios are given below:

  • Connect to localhost on port 9200 with no authentication over a plain connection
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://localhost:9200";

Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with no authentication
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

or,

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://remote-host-name";

Properties properties = new Properties();
properties.put("useSSL", "true");

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host with HTTP Basic authentication over an SSL/TLS connection on the default SSL/TLS port. Note - if a username and password are provided and auth property is not provided, basic auth is implicitly used.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name";
String user = "username";
String password = "password";

Connection con = DriverManager.getConnection(url, user, password);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

or,

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://remote-host-name";

Properties properties = new Properties();
properties.put("useSSL", "true");
properties.put("user", "username");
properties.put("password", "password");

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host with HTTP Basic authentication over an SSL/TLS connection, allowing any self-signed certificate and optionally turning off hostname verification. This may be useful for a dev/test setup.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://remote-host-name";

Properties properties = new Properties();
properties.put("useSSL", "true");
properties.put("trustSelfSigned", "true");

// uncomment below to turn off hostname verification
// properties.put("hostnameVerification", "false");

properties.put("user", "username");
properties.put("password", "password");

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication. The driver will determine the credentials used to sign the request just like the standard aws-sdk i.e. in standard directories, environment variables etc.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name?auth=aws_sigv4";

Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

or,

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

Properties properties = new Properties();
properties.put("auth", "aws_sigv4");

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication, explicitly specifying the AWSCredentialProvider to use
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

Properties properties = new Properties();
properties.put("awsCredentialsProvider", new EnvironmentVariableCredentialsProvider());

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication, explicitly specifying the region to use in the request signing.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name?auth=aws_sigv4&region=us-west-1";

Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

or,

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

Properties properties = new Properties();
properties.put("auth", "aws_sigv4");
properties.put("region", "us-west-2");

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

Connecting using the DataSource interface

The driver also provides a javax.sql.DataSource implementation via the com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource class that can be used to obtain a connection. Here are some typical code samples:

  • Connect to localhost on port 9200 with no authentication over a plain connection
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://localhost:9200";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);

Connection con = ds.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with no authentication
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);

Connection con = ds.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host with HTTP Basic authentication over an SSL/TLS connection on the default SSL/TLS port.
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://https://remote-host-name";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);

Connection con = ds.getConnection(url, "user", "password");
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication. The driver will determine the credentials used to sign the request just like the standard aws-sdk i.e. in standard directories, environment variables etc.
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://https://remote-host-name?auth=aws_sigv4";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);

Connection con = ds.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication, explicitly specifying the AWSCredentialProvider to use
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://https://remote-host-name?auth=aws_sigv4&region=us-west-1";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);
ds.setAwsCredentialProvider(new EnvironmentVariableCredentialsProvider());

Connection con = ds.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();
  • Connect to a remote host on default SSL port with AWS Sig V4 authentication, explicitly specifying the region to use in the request signing.
import java.sql.Connection;
import java.sql.Statement;
import javax.sql.DataSource;

import com.amazon.opendistroforelasticsearch.jdbc.ElasticsearchDataSource;

.
.
String url = "jdbc:elasticsearch://https://remote-host-name?auth=aws_sigv4&region=us-west-1";

ElasticsearchDataSource ds = new ElasticsearchDataSource();
ds.setUrl(url);

Connection con = ds.getConnection(url);
Statement st = con.createStatement();
.
// use the connection
.
// close connection
con.close();

Download and Installation

The driver will be available through standard open source repositories for Java artifacts.

Building from source

The driver is built as a shadow jar so that its dependencies are bundled within itself. This way no additional libraries besides the driver jar need to be placed on an application classpath for the driver to be used. The namespaces of the bundled dependencies are modified to ensure they do not conflict with other classes on the application classpath.

Run unit tests and build the driver jar

./gradlew clean test shadowJar

Build the driver jar without unit tests

./gradlew shadowJar

Publish the built driver jar to local maven repo

./gradlew publishToMavenLocal

Documentation

Please refer to the documentation for detailed information on installing and configuring opendistro-elasticsearch-security plugin.

Code of Conduct

This project has adopted an Open Source Code of Conduct.

Security issue notifications

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page. Please do not create a public GitHub issue.

Licensing

See the LICENSE file for our project's licensing. We will ask you to confirm the licensing of your contribution.

Copyright

Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

sql-jdbc's People

Contributors

abbashus avatar aetter avatar alex-sherwin avatar anandshah123 avatar arsen-es avatar carlmeadows avatar chloe-zh avatar coupelon avatar dai-chen avatar davidcui1225 avatar echo-42 avatar elfisher avatar gaiksaya avatar galkk avatar jianfei-li avatar joshuali925 avatar penghuo avatar qreshi avatar rishabh6788 avatar rupal-bq avatar salamanderrex avatar tbrugz avatar vinjosh avatar zhongnansu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sql-jdbc's Issues

Can not parse 2020-03-23T09:28:48+00:00 as a Timestamp

The format of Timestamp is different in our elasticSearch, which we got is like
2020-03-23T09:28:48+00:00

I changed the source code of jdbc/types/TimestampType.java
from

        // Timestamp.valueOf() does not like timezone information
        if (value.length() > 23) {
            if (value.length() == 24 && value.charAt(23) == 'Z') {
                value = value.substring(0, 23);
            }
            else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
                // 'calendar' parameter takes precedence
                if (calendar == null) {
                    calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT" + value.substring(23)));
                }
                value = value.substring(0, 23);
            }
        }

to

        // Timestamp.valueOf() does not like timezone information
        if (value.length() > 23) {
            if (value.length() == 24 && value.charAt(23) == 'Z') {
                value = value.substring(0, 23);
            } else {
				int delimiterIndex = value.length() - 6;
				if (value.charAt(delimiterIndex) == '+'
					  || value.charAt(delimiterIndex) == '-') {
				    // 'calendar' parameter takes precedence
				    if (calendar == null) {
				        calendar = Calendar.getInstance(
				        		TimeZone.getTimeZone("GMT" + value.substring(delimiterIndex)));
				    }
				    value = value.substring(0, delimiterIndex);
				}
			}
        }

It seems the compatibility is better.

Failed to read index from Dbeaver

I am using a Dbeaver to access Elasticsearch service on AWS. I am facing an error while trying to access an index having around 100 fields. Though I am able to query the index from the editor, I can't see the schema in the data explorer.
Please find below image for more details about the error.
image

SQuirrel and JDBC driver SQL date format

Trying to select date fields from ES using JDBC driver and SQuirrel returns errors to the execution logs. All the date fields are seen as <Error> within the result set.

The select I'm trying to execute is:
select * from kibana_sample_data_logs;

SQuirrel logs:

2019-04-01 16:03:22,016 [Thread-4] ERROR net.sourceforge.squirrel_sql.fw.sql.ResultSetReader - Error reading column data, column index = 9
java.sql.SQLDataException: Can not parse 2019-04-13 12:58:48.352Z as a Timestamp
at com.amazon.opendistroforelasticsearch.jdbc.types.TypeHelper.stringConversionException(TypeHelper.java:33)
at com.amazon.opendistroforelasticsearch.jdbc.types.TimestampType.asTimestamp(TimestampType.java:85)
at com.amazon.opendistroforelasticsearch.jdbc.types.TimestampType.fromValue(TimestampType.java:46)
at com.amazon.opendistroforelasticsearch.jdbc.types.TimestampType.fromValue(TimestampType.java:29)
at com.amazon.opendistroforelasticsearch.jdbc.types.BaseTypeConverter.convert(BaseTypeConverter.java:58)
at com.amazon.opendistroforelasticsearch.jdbc.ResultSetImpl.getObjectX(ResultSetImpl.java:530)
at com.amazon.opendistroforelasticsearch.jdbc.ResultSetImpl.getTimestampX(ResultSetImpl.java:326)
at com.amazon.opendistroforelasticsearch.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:315)
at net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestamp.readResultSet(DataTypeTimestamp.java:505)
at net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.CellComponentFactory.readResultSet(CellComponentFactory.java:503)
at net.sourceforge.squirrel_sql.fw.sql.ResultSetReader.doContentTabRead(ResultSetReader.java:613)
at net.sourceforge.squirrel_sql.fw.sql.ResultSetReader.readRow(ResultSetReader.java:184)
at net.sourceforge.squirrel_sql.fw.datasetviewer.ResultSetDataSet.createRow(ResultSetDataSet.java:242)
at net.sourceforge.squirrel_sql.fw.datasetviewer.ResultSetDataSet._setResultSet(ResultSetDataSet.java:208)
at net.sourceforge.squirrel_sql.fw.datasetviewer.ResultSetDataSet.setSqlExecutionTabResultSet(ResultSetDataSet.java:133)
at net.sourceforge.squirrel_sql.client.session.mainpanel.SQLExecutionHandler.sqlResultSetAvailable(SQLExecutionHandler.java:431)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.processResultSet(SQLExecuterTask.java:540)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.processQuery(SQLExecuterTask.java:403)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:209)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NumberFormatException: For input string: "352Z00000"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at java.sql.Timestamp.valueOf(Timestamp.java:255)
at com.amazon.opendistroforelasticsearch.jdbc.types.TimestampType.asTimestamp(TimestampType.java:78)
... 19 more

Result set concurrency incorrectly passed as result set holdability

When attempting to get Apache Spark to work with this JDBC driver, I came across an issue where the following exception is raised in the driver:

java.sql.SQLNonTransientException: Only HOLD_CURSORS_OVER_COMMIT holdability is supported.
        at com.amazon.opendistroforelasticsearch.jdbc.ConnectionImpl.validateResultSetHoldability(ConnectionImpl.java:275)
        at com.amazon.opendistroforelasticsearch.jdbc.ConnectionImpl.validateResultSetCharacteristics(ConnectionImpl.java:260)
        at com.amazon.opendistroforelasticsearch.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:282)
        at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD.compute(JDBCRDD.scala:300)
        at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
        at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
        at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
        at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
        at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
        at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
        at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
        at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
        at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:99)
        at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:55)
        at org.apache.spark.scheduler.Task.run(Task.scala:121)
        at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
        at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
        at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

In this line:

https://github.com/opendistro-for-elasticsearch/sql-jdbc/blob/625614647c5110daa4e524143d55ecabb8e50794/src/main/java/com/amazon/opendistroforelasticsearch/jdbc/ConnectionImpl.java#L282

it appears that resultSetConcurrency is supplied twice to the validateResultSetCharacteristics method call, when it should follow the approach of this:

https://github.com/opendistro-for-elasticsearch/sql-jdbc/blob/625614647c5110daa4e524143d55ecabb8e50794/src/main/java/com/amazon/opendistroforelasticsearch/jdbc/ConnectionImpl.java#L250

I forked the repo and built my own driver with the following fix and it resolved the issue:

mixja@8ac4cc9

Can support nested type?

PUT /obj
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text"
        },
        "car": {
          "type": "nested",
          "properties": {
            "make": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "settings":{
      "index":{
          "number_of_shards":1,
          "number_of_replicas":1
      }
  }
}
PUT /obj/_doc/1
{
  "name" : "Zach",
  "car" : [
    {
      "make" : "Saturn",
      "model" : "SL"
    },
    {
      "make" : "Subaru",
      "model" : "Imprezza"
    }
  ]
}

PUT /obj/_doc/2
{
  "name" : "Rach",
  "car" : [
    {
      "make" : "Naturn",
      "model" : "NL"
    },
    {
      "make" : "Wubaru",
      "model" : "Laprezza"
    },
    {
      "make" : "Siri",
      "model" : "Paprezza"
    }
  ]
}

I want to get the all elements of array. like

select  * from obj.car

Error retrieving data from opendistro from Tableau

Hi,
I got opendistro-for-elasticsearch running locally on my laptop and loaded a simple table with four columns (id, latitude, longitude, shop_category) with shop_category being a text type field

Using tableau desktop and sql-jdbc driver, I was able to connect to the table and see the values in datasource view but when trying to create a worksheet with one of the columns, Tableau was throwing an error saying "There was a Java error".

Version Info:
opendistro-for-elasticsearch: 1.6.0
sql-jdbc driver: opendistro-sql-jdbc-1.6.0.0-SNAPSHOT.jar
java while running opendistro: openjdk12

Enabling logs at sql-jdbc, here is the error i see

[2020-04-15 19:45:54.918][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 >> "{"query":"SELECT `poi`.`brand` AS `brand`,\n  `poi`.`shop_category` AS `shop_category`\nFROM `poi`\nGROUP BY `poi`.`brand`,\n  `poi`.`shop_category`"}"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "HTTP/1.1 200 OK[\r][\n]"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "content-type: application/json; charset=UTF-8[\r][\n]"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "content-length: 187[\r][\n]"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "[\r][\n]"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "{[\n]"
[2020-04-15 19:45:55.359][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "  "error": {[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "    "reason": "There was internal problem at backend",[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "    "details": "invalid value operation on MISSING_VALUE",[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "    "type": "IllegalStateException"[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "  },[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "  "status": 500[\n]"
[2020-04-15 19:45:55.360][DEBUG][Thread-pool-3-thread-11][ApacheHttpTransport@a78fda6] http-outgoing-11 << "}"

In opendistro, i am seeing following error stack trace

Incoming request /_opendistro/_sql?format=jdbc: SELECT `poi`.`brand` AS `brand`,
  `poi`.`shop_category` AS `shop_category`
FROM `poi`
GROUP BY `poi`.`brand`,
  `poi`.`shop_category`
[2020-04-14T17:45:29,206][WARN ][c.a.o.s.e.f.PrettyFormatRestExecutor] [WMac5179515] Error happened in pretty formatter
java.lang.IllegalStateException: invalid value operation on MISSING_VALUE
	at com.amazon.opendistroforelasticsearch.sql.expression.model.ExprValue.value(ExprValue.java:23) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.BindingTupleResultSet.lambda$buildDataRows$1(BindingTupleResultSet.java:55) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_202]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[?:1.8.0_202]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_202]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[?:1.8.0_202]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_202]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_202]
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[?:1.8.0_202]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.BindingTupleResultSet.buildDataRows(BindingTupleResultSet.java:58) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.BindingTupleResultSet.<init>(BindingTupleResultSet.java:35) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.Protocol.loadResultSet(Protocol.java:78) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.Protocol.<init>(Protocol.java:65) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.PrettyFormatRestExecutor.execute(PrettyFormatRestExecutor.java:71) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.format.PrettyFormatRestExecutor.execute(PrettyFormatRestExecutor.java:47) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.AsyncRestExecutor.doExecuteWithTimeMeasured(AsyncRestExecutor.java:161) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.executor.AsyncRestExecutor.lambda$async$1(AsyncRestExecutor.java:121) ~[?:?]
	at com.amazon.opendistroforelasticsearch.sql.utils.LogUtils.lambda$withCurrentContext$0(LogUtils.java:72) ~[?:?]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:633) [elasticsearch-7.6.1.jar:7.6.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_202]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_202]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]

Select using multi indexes

Hi,

I am using the driver with jasper report and it works like a charm. However, I cannot make queries such as:

select * from logtstash*

This query is working using the open distro plugin via the Rest API.

Am I missing something ?

Thanks,

Post submission only supports iso-8859-1 encoding

ApacheHttpTransport line 263 HttpPost.setEntity when creating a StringEntity without specifying the encoding, ISO-8859-1 is used by default and no encoding can be set such as UTF-8.

I am using version 1.4.0.0

1.4.0.0:

ApacheHttpTransport:
request.setEntity(new StringEntity(body));

StringEntity:

public StringEntity(final String string)
           throws UnsupportedEncodingException {
      this(string, ContentType.DEFAULT_TEXT);
}

public StringEntity(final String string, final ContentType contentType) throws UnsupportedCharsetException {
        super();
        Args.notNull(string, "Source string");
        Charset charset = contentType != null ? contentType.getCharset() : null;
        if (charset == null) {
            charset = HTTP.DEF_CONTENT_CHARSET;
        }
        this.content = string.getBytes(charset);
        if (contentType != null) {
            setContentType(contentType.toString());
        }
    }

ContentType:
public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;
public static final ContentType TEXT_PLAIN = create( "text/plain", Consts.ISO_8859_1);

expected:
request.setEntity(new StringEntity(body,ContentType.APPLICATION_JSON));

Re-Open Build from source to make compatible for Elasticsearch 7.6.2

Please reopen this issue if you have questions

Originally posted by @anirudha in #78 (comment)

After build from source, I have the opendistro_sql-1.7.0.0-SNAPSHOT.jar, then I use it in dbeaver.
The problem is the same, bad request, since I saw in https://opendistro.github.io/for-elasticsearch-docs/docs/install/plugins/, it should install the opendistro-sql-xxx.zip, when I following the URL, the result said that the plugins for 7.6.1.
How I can use it in 7.6.2? Please give a hint...

Regards,
Fadjar Tandabawana

select date_format error

The query "SELECT date_format(mydate, 'yyyy-mm-dd') AS date, COUNT(*) AS count, SUM('aaa') AS sum FROM table GROUP BY date_format(mydate, 'yyyy-mm-dd')" got error w/ JDBC, but works w/o JDBC.

The error, com.amazon.opendistroforelasticsearch.jdbc.protocol.exceptions.InternalServerErrorException.

JDBC TEST 400

    @Test
    public void queryTest() throws SQLException {
        String url = "jdbc:elasticsearch://node01:9200";
        Properties properties = new Properties();
        //properties.put("user", "test_admin");
        //properties.put("password", "x-pack-test-password");

        Connection connection = DriverManager.getConnection(url, properties);

        try (Statement statement = connection.createStatement()) {
            ResultSet results = statement.executeQuery("SELECT name, page_count FROM library");
        }
    }

response:

java.sql.SQLException: Error executing query

	at com.amazon.opendistroforelasticsearch.jdbc.StatementImpl.executeQueryRequest(StatementImpl.java:84)
	at com.amazon.opendistroforelasticsearch.jdbc.StatementImpl.executeQueryX(StatementImpl.java:61)
	at com.amazon.opendistroforelasticsearch.jdbc.StatementImpl.executeQuery(StatementImpl.java:54)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: com.amazon.opendistroforelasticsearch.jdbc.protocol.http.HttpException: HTTP Code: 400. Message: Bad Request. Raw response received: {"error":{"root_cause":[{"type":"invalid_index_name_exception","reason":"Invalid index name [_opendistro], must not start with '_', '-', or '+'","index_uuid":"_na_","index":"_opendistro"}],"type":"invalid_index_name_exception","reason":"Invalid index name [_opendistro], must not start with '_', '-', or '+'","index_uuid":"_na_","index":"_opendistro"},"status":400}
	at com.amazon.opendistroforelasticsearch.jdbc.protocol.http.JsonHttpResponseHandler.checkResponseForErrors(JsonHttpResponseHandler.java:83)
	at com.amazon.opendistroforelasticsearch.jdbc.protocol.http.JsonHttpResponseHandler.handleResponse(JsonHttpResponseHandler.java:52)
	at com.amazon.opendistroforelasticsearch.jdbc.protocol.http.JsonHttpResponseHandler.handleResponse(JsonHttpResponseHandler.java:45)
	at com.amazon.opendistroforelasticsearch.jdbc.protocol.http.JsonHttpProtocol.execute(JsonHttpProtocol.java:88)
	at com.amazon.opendistroforelasticsearch.jdbc.StatementImpl.executeQueryRequest(StatementImpl.java:72)
	... 25 more

image

Can not parse 2019-10-01 01:24:16.191Z as a Timestamp

Hi, I'm running into issues with timestamps in our elasticSearch, the JDBC driver is returning the following.

Can not parse 2019-10-01 01:24:16.191Z as a Timestamp

this is when I include one of our timestamp fields in the select columns.

I'm looking at your jdbc/types/TimestampType.java routine and I think it's off by 1 char, thinking this should be looking at Z as the 24th char not 23rd but it seems to work with removal of T so I'm confused.

Any thoughts on what might be happening here?

// Make some effort to understand ISO format
if (value.length() > 11 && value.charAt(10) == 'T') {
value = value.replace('T', ' ');
}
// Timestamp.valueOf() does not like timezone information
if (value.length() > 23) {
if (value.length() == 24 && value.charAt(23) == 'Z') {
value = value.substring(0, 23);
}
else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
// 'calendar' parameter takes precedence
if (calendar == null) {
calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT" + value.substring(23)));
}
value = value.substring(0, 23);
}
}

Thank you for your work on this project, this is going to come in really handy.

should setReadonly method throw Exception?

I use Sharding-proxy(use HikariPool), But I have no way to explicitly specify database isReadOnly,at least for now, resulting in a SQLNonTransientException ("read-only mode can not be disabled."), causing the connection to fail. I noticed that other similar jdbc drives the setReadOnly method are not will throw exception, such as

sql-server(https://github.com/microsoft/mssql-jdbc/blob/dev/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java),

H2(https://github.com/h2database/h2database/blob/master/h2/src/main/org/h2/jdbc/JdbcConnection.java),

I don't know how to solve it

DatabaseMetaData.getColumns(null, null, tableNamePattern, null) returns no columns

I'm running opendistro docker image as indicated in https://opendistro.github.io/for-elasticsearch-docs/docs/install/docker/

After initializing the container, the only table avaiable seems to be security-auditlog-<yyyy.MM.dd>

If I try to query for avaiable columns with DatabaseMetaData.getColumns(null, null, tableNamePattern, "%") it returns the table's columns as expected, but if I try to query for avaiable columns with null on columnNamePattern - as DatabaseMetaData.getColumns(null, null, tableNamePattern, null) - it returns no rows.

The issue seems to be that, if columnNamePattern is null, the query sent to the server is DESCRIBE TABLES LIKE security-auditlog-<yyyy.MM.dd> COLUMNS LIKE null

New Maven Endpoint for ODFE

Hi,
The maven endpoint for ODFE has changed from https://oss.sonatype.org/service/local/staging/deploy/maven2 to https://aws.oss.sonatype.org/service/local/staging/deploy/maven2

The login credentials are the same as before. However, the user token has been updated. Infra team will updated the user token credentials (used in maven workflows). However, the URLs in the codebase needs to be updated by the plugin teams.

Currently, the old URL and user token is active. Infra team will update the token on 6/22. Make sure to update the URLs by then

More details: https://issues.sonatype.org/browse/OSSRH-47276

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.