├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── connector-elasticsearch ├── pom.xml └── src │ ├── main │ ├── config │ │ ├── ElasticSearchConnector.xml │ │ ├── ElasticSearchDataStore.xml │ │ ├── connector-application.conf │ │ └── log4j.properties │ ├── include │ │ ├── LICENSE │ │ └── NOTICE │ ├── java │ │ └── com │ │ │ └── stratio │ │ │ └── connector │ │ │ └── elasticsearch │ │ │ └── core │ │ │ ├── ElasticsearchConnector.java │ │ │ ├── configuration │ │ │ ├── ConfigurationOptions.java │ │ │ └── ElasticsearchClientConfiguration.java │ │ │ ├── connection │ │ │ ├── ElasticSearchConnectionHandler.java │ │ │ ├── NodeConnection.java │ │ │ └── TransportConnection.java │ │ │ └── engine │ │ │ ├── ElasticsearchMetadataEngine.java │ │ │ ├── ElasticsearchQueryEngine.java │ │ │ ├── ElasticsearchStorageEngine.java │ │ │ ├── metadata │ │ │ ├── AddColumnHandler.java │ │ │ ├── AlterTableFactory.java │ │ │ ├── AlterTableHandler.java │ │ │ ├── ESIndexType.java │ │ │ └── MetadataCreator.java │ │ │ ├── query │ │ │ ├── ConnectorQueryBuilder.java │ │ │ ├── ConnectorQueryData.java │ │ │ ├── ConnectorQueryExecutor.java │ │ │ ├── ConnectorQueryParser.java │ │ │ ├── ESProjectParsedValidator.java │ │ │ └── functions │ │ │ │ ├── ESFunction.java │ │ │ │ ├── Fuzzy.java │ │ │ │ ├── Match.java │ │ │ │ ├── MatchPhrase.java │ │ │ │ ├── MatchPrefix.java │ │ │ │ ├── MultiMatch.java │ │ │ │ └── MultiMatchFuzzy.java │ │ │ └── utils │ │ │ ├── Constants.java │ │ │ ├── ContentBuilderCreator.java │ │ │ ├── FilterBuilderCreator.java │ │ │ ├── IndexRequestBuilderCreator.java │ │ │ ├── QueryBuilderFactory.java │ │ │ ├── RowSorter.java │ │ │ ├── SelectorUtils.java │ │ │ └── TypeConverter.java │ ├── template │ │ └── ElasticSearchConnector │ └── unix │ │ ├── files_and_dirs │ │ ├── DEBIAN │ │ │ ├── conffiles │ │ │ └── copyright │ │ └── etc │ │ │ ├── default │ │ │ └── elasticsearch_connector │ │ │ └── init.d │ │ │ └── connector_elasticsearch │ │ └── scripts │ │ ├── post │ │ ├── postinst │ │ ├── pre │ │ └── preinst │ ├── resources │ └── connector-reference.conf │ └── test │ ├── java │ └── com │ │ └── stratio │ │ └── connector │ │ └── elasticsearch │ │ └── core │ │ ├── ElasticsearchConnectorTest.java │ │ ├── configuration │ │ └── ElasticsearchClientConfigurationTest.java │ │ ├── connection │ │ ├── ConnectionHandleTest.java │ │ ├── NodeConnectionTest.java │ │ └── TransportConnectionTest.java │ │ └── engine │ │ ├── ElasticsearchMetadataEngineTest.java │ │ ├── ElasticsearchQueryEngineTest.java │ │ ├── ElasticsearchStorageEngineExceptionTest.java │ │ ├── ElasticsearchStorageEngineTest.java │ │ ├── metadata │ │ └── AlterTableFactoryTest.java │ │ ├── query │ │ ├── ConnectorQueryBuilderAggregationsTest.java │ │ ├── ConnectorQueryBuilderTest.java │ │ ├── ConnectorQueryExecutorTest.java │ │ ├── ConnectorQueryParserTest.java │ │ ├── ESProjectParsedValidatorTest.java │ │ ├── functions │ │ │ ├── ESFunctionTest.java │ │ │ ├── FuzzyMultiMatchTest.java │ │ │ ├── FuzzyTest.java │ │ │ ├── MatchPhraseTest.java │ │ │ ├── MatchPrefixTest.java │ │ │ ├── MatchTest.java │ │ │ └── MultiMatchTest.java │ │ └── metadata │ │ │ └── MetadataCreatorTest.java │ │ └── utils │ │ ├── ContentBuilderCreatorTest.java │ │ ├── FilterBuilderCreatorTest.java │ │ ├── IndexRequestBuilderCreatorExceptionTest.java │ │ ├── IndexRequestBuilderCreatorTest.java │ │ ├── QueryBuilderFactoryTest.java │ │ ├── RowSorterTest.java │ │ ├── SelectorUtilsTest.java │ │ └── TypeConverterTest.java │ └── resources │ ├── ElasticSearchConnector.xml │ ├── ElasticSearchDataStore.xml │ └── log4j.xml ├── doc ├── pom.xml └── src │ └── site │ └── sphinx │ ├── 0_concepts.rst │ ├── 1_functions.rst │ ├── 2_examples.rst │ ├── First_Steps.rst │ ├── about.rst │ ├── conf.py │ └── index.rst └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | src/test/efficiencyFiles/ 2 | *.asc 3 | data 4 | target 5 | *.swp 6 | .clover 7 | *.out 8 | */**/*.out 9 | */**/target 10 | *.log 11 | */**/data 12 | *.project 13 | .settings/ 14 | *.classpath 15 | *.class 16 | .idea 17 | *.iml 18 | .orig 19 | *.iws 20 | *~ 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doc/src/site/sphinx/_themes/stratio"] 2 | path = doc/src/site/sphinx/_themes/stratio 3 | url = https://github.com/Stratio/sphinx-theme-stratio.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.5.4 (November 2015) 4 | 5 | * Adapted to Stratio Crossdata 0.5.1 6 | 7 | ## 0.5.3 (October 2015) 8 | 9 | * Adapted to Stratio Crossdata 0.5.0 10 | 11 | ## 0.5.2 (September 2015) 12 | 13 | * Adapted to Stratio Crossdata 0.4.3 14 | 15 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Stratio Connector-Elasticsearch 2 | Copyright 2014 Stratio 3 | 4 | This product includes software developed at 5 | Stratio (http://www.openstratio.org/). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | *This project has been discontinued in favour of [Stratio Crossdata](https://github.com/Stratio/Crossdata), which is a data federation system leveraging Apache Spark capabilities.* 3 | 4 | # About # 5 | 6 | 7 | The Stratio Connector-Elasticsearch allows [Stratio Crossdata] () to interact with ElasticSearch. 8 | 9 | ## How to use Stratio Connector-Elasticsearch ## 10 | 11 | Requirements, installation and use of the connector can be found in [about.rst] () 12 | 13 | There also exists a [First Steps] () document where through an easy example the main features of this connector are illustrated. 14 | 15 | # License # 16 | 17 | Licensed to STRATIO (C) under one or more contributor license 18 | agreements. See the NOTICE file distributed with this work for 19 | additional information regarding copyright ownership. The STRATIO (C) 20 | licenses this file to you under the Apache License, Version 2.0 (the 21 | "License"); you may not use this file except in compliance with the 22 | License. You may obtain a copy of the License at 23 | 24 | http://www.apache.org/licenses/LICENSE-2.0 25 | 26 | Unless required by applicable law or agreed to in writing, software 27 | distributed under the License is distributed on an "AS IS" BASIS, 28 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | See the License for the specific language governing permissions and 30 | limitations under the License. 31 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/config/ElasticSearchDataStore.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 | elasticsearch 24 | 0.4.0 25 | 26 | 27 | Hosts 28 | The list of hosts ips 29 | 30 | 31 | Native Ports 32 | The list of hosts native ports 33 | 34 | 35 | Restful Ports 36 | The list of hosts restful ports 37 | 38 | 39 | Cluster Name 40 | The name of the ElasticSearch Cluster 41 | 42 | 43 | 44 | ALL_INDEXED 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/config/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to STRATIO (C) under one or more contributor license agreements. 3 | # See the NOTICE file distributed with this work for additional information 4 | # regarding copyright ownership. The STRATIO (C) licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | log4j.rootLogger=DEBUG, STDOUT 20 | log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender 21 | log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout 22 | log4j.appender.STDOUT.layout.ConversionPattern=[Driver] %d{dd-MM-yyyy HH:mm:ss.SSS} [%p|%c{1}] %m%n 23 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/include/NOTICE: -------------------------------------------------------------------------------- 1 | Stratio Meta 2 | Copyright 2014 Stratio 3 | 4 | This product includes software developed at 5 | Stratio (http://www.openstratio.org/). -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/ElasticsearchConnector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core; 20 | 21 | import com.stratio.connector.commons.TimerJ; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | import com.stratio.connector.commons.CommonsConnector; 26 | import com.stratio.connector.commons.util.ManifestUtil; 27 | import com.stratio.connector.elasticsearch.core.connection.ElasticSearchConnectionHandler; 28 | import com.stratio.connector.elasticsearch.core.engine.ElasticsearchMetadataEngine; 29 | import com.stratio.connector.elasticsearch.core.engine.ElasticsearchQueryEngine; 30 | import com.stratio.connector.elasticsearch.core.engine.ElasticsearchStorageEngine; 31 | import com.stratio.crossdata.common.connector.IConfiguration; 32 | import com.stratio.crossdata.common.connector.IMetadataEngine; 33 | import com.stratio.crossdata.common.connector.IQueryEngine; 34 | import com.stratio.crossdata.common.connector.IStorageEngine; 35 | import com.stratio.crossdata.common.exceptions.ExecutionException; 36 | import com.stratio.crossdata.common.exceptions.InitializationException; 37 | import com.stratio.crossdata.common.metadata.IMetadata; 38 | import com.stratio.crossdata.connectors.ConnectorApp; 39 | 40 | /** 41 | * This class implements the connector for Elasticsearch. 42 | */ 43 | public class ElasticsearchConnector extends CommonsConnector { 44 | 45 | /** 46 | * The Log. 47 | */ 48 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 49 | 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @throws InitializationException if an error happens. 55 | */ 56 | public ElasticsearchConnector() throws InitializationException { 57 | super("/ElasticSearchConnector.xml", "/ElasticSearchDataStore.xml"); 58 | 59 | } 60 | 61 | /** 62 | * The main method. 63 | * 64 | * @param args the arguments 65 | * @throws InitializationException the initialization exception 66 | */ 67 | public static void main(String[] args) throws InitializationException { 68 | 69 | ElasticsearchConnector elasticsearchConnector = new ElasticsearchConnector(); 70 | ConnectorApp connectorApp = new ConnectorApp(); 71 | connectorApp.startup(elasticsearchConnector); 72 | elasticsearchConnector.attachShutDownHook(); 73 | 74 | } 75 | 76 | 77 | /** 78 | * Create a connection to Elasticsearch. The client will be a transportClient by default unless stratio nodeClient 79 | * is specified. 80 | * 81 | * @param configuration the connection configuration. It must be not null. 82 | * @throws InitializationException if a error happens. 83 | */ 84 | 85 | @Override 86 | @TimerJ 87 | public void init(IConfiguration configuration) throws InitializationException { 88 | 89 | connectionHandler = new ElasticSearchConnectionHandler(configuration); 90 | 91 | } 92 | 93 | @Override 94 | public void restart() throws ExecutionException { 95 | 96 | } 97 | 98 | 99 | /** 100 | * Return the StorageEngine. 101 | * 102 | * @return the StorageEngine 103 | */ 104 | @Override 105 | @TimerJ 106 | public IStorageEngine getStorageEngine() { 107 | 108 | return new ElasticsearchStorageEngine(connectionHandler); 109 | 110 | } 111 | 112 | /** 113 | * Run the shutdown. 114 | */ 115 | @TimerJ 116 | public void attachShutDownHook() { 117 | Runtime.getRuntime().addShutdownHook(new Thread() { 118 | @Override 119 | public void run() { 120 | try { 121 | shutdown(); 122 | } catch (ExecutionException e) { 123 | logger.error("Fail ShutDown"); 124 | } 125 | } 126 | }); 127 | } 128 | 129 | /** 130 | * Return the QueryEngine. 131 | * 132 | * @return the QueryEngine 133 | */ 134 | @Override 135 | @TimerJ 136 | public IQueryEngine getQueryEngine() { 137 | 138 | return new ElasticsearchQueryEngine(connectionHandler); 139 | } 140 | 141 | /** 142 | * Return the MetadataEngine. 143 | * 144 | * @return the MetadataEngine 145 | */ 146 | @Override 147 | @TimerJ 148 | public IMetadataEngine getMetadataEngine() { 149 | 150 | return new ElasticsearchMetadataEngine(connectionHandler); 151 | } 152 | 153 | 154 | } 155 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/configuration/ConfigurationOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.configuration; 20 | 21 | import com.stratio.connector.elasticsearch.core.engine.utils.Constants; 22 | 23 | /** 24 | * This enum has the options for Elasticsearch. 25 | * Created by jmgomez on 1/09/14. 26 | */ 27 | public enum ConfigurationOptions { 28 | 29 | /** 30 | * The elasticserach node type property. 31 | */ 32 | NODE_TYPE("node_type", "node_type", Constants.FALSE), 33 | /** 34 | * The elasticserach node data property. 35 | */ 36 | NODE_DATA("node.data", "node.data",Constants.FALSE), 37 | /** 38 | * The elasticserach node master property. 39 | */ 40 | NODE_MASTER("node.master", "node.master",Constants.FALSE), 41 | /** 42 | * The elasticserach transfer sniff type property. 43 | */ 44 | TRANSPORT_SNIFF("client.transport.sniff", "client.transport.sniff",Constants.TRUE), 45 | /** 46 | * The elastichseach cluser name. 47 | */ 48 | CLUSTER_NAME("Cluster Name","cluster.name","", "clusterName"), 49 | /** 50 | * The hosts ip. 51 | */ 52 | HOST("Hosts","Hosts", new String[] { "localhost" }), 53 | /** 54 | * The hosts ports. 55 | */ 56 | PORT("Native Ports", "Native Ports",new String[] { "c" }), 57 | /** 58 | * The elasticsearch coerce property. 59 | */ 60 | COERCE("index.mapping.coerce","index.mapping.coerce", Constants.FALSE), 61 | /** 62 | * The elasticsearch mapper dynamic property. 63 | */ 64 | DYNAMIC("index.mapper.dynamic", "index.mapper.dynamic",Constants.FALSE); 65 | 66 | /** 67 | * The name of the option in crossdata manifest. 68 | */ 69 | private final String manifestOption; 70 | /** 71 | * The default value of the options. 72 | */ 73 | private final String[] defaultValue; 74 | /** 75 | * The option name in elasticsearch. 76 | */ 77 | private final String elasticSearchOption; 78 | 79 | /** 80 | * Constructor. 81 | * 82 | * @param manifestOption the name of the option. 83 | * @param defaultValue the default value of the option. 84 | */ 85 | ConfigurationOptions(String manifestOption, String elasticSearchOption, String... defaultValue) { 86 | this.manifestOption = manifestOption; 87 | this.defaultValue = defaultValue; 88 | this.elasticSearchOption = elasticSearchOption; 89 | 90 | } 91 | 92 | /** 93 | * return the default value. 94 | * 95 | * @return the default value. 96 | */ 97 | public String[] getDefaultValue() { 98 | return defaultValue.clone(); 99 | } 100 | 101 | /** 102 | * Return the option name defined in the manifest. 103 | * 104 | * @return the option name. 105 | */ 106 | public String getManifestOption() { 107 | return manifestOption; 108 | } 109 | 110 | 111 | 112 | /** 113 | * Return the option name to ElasticSearch. 114 | * 115 | * @return the option name. 116 | */ 117 | public String getElasticSearchOption() { 118 | return elasticSearchOption; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/configuration/ElasticsearchClientConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.configuration; 20 | 21 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.CLUSTER_NAME; 22 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.COERCE; 23 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.DYNAMIC; 24 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.HOST; 25 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.NODE_DATA; 26 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.NODE_MASTER; 27 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.PORT; 28 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.TRANSPORT_SNIFF; 29 | 30 | import java.util.HashMap; 31 | import java.util.Map; 32 | 33 | import com.stratio.connector.commons.util.PropertyValueRecovered; 34 | import com.stratio.crossdata.common.exceptions.ExecutionException; 35 | import org.elasticsearch.common.settings.ImmutableSettings; 36 | import org.elasticsearch.common.settings.Settings; 37 | import org.elasticsearch.common.transport.InetSocketTransportAddress; 38 | import org.elasticsearch.common.transport.TransportAddress; 39 | 40 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 41 | 42 | /** 43 | * The configuration for Elasticsearch. 44 | */ 45 | 46 | public final class ElasticsearchClientConfiguration { 47 | 48 | /** 49 | * Private constructor. 50 | */ 51 | private ElasticsearchClientConfiguration() { 52 | } 53 | 54 | /** 55 | * Retrieves the Settings using either the Elasticsearch client configuration or the configuration file. 56 | * 57 | * @param configuration the configuration 58 | * @return the settings 59 | */ 60 | public static Settings getSettings(ConnectorClusterConfig configuration) { 61 | 62 | Map setting = new HashMap(); 63 | setting.put(NODE_DATA.getElasticSearchOption(), recoverdOptionValue(configuration.getConnectorOptions(), NODE_DATA)); 64 | setting.put(NODE_MASTER.getElasticSearchOption(), recoverdOptionValue(configuration.getConnectorOptions(), NODE_MASTER)); 65 | setting.put(TRANSPORT_SNIFF.getElasticSearchOption(), 66 | recoverdOptionValue(configuration.getConnectorOptions(), TRANSPORT_SNIFF)); 67 | setting.put(COERCE.getElasticSearchOption(), recoverdOptionValue(configuration.getConnectorOptions(), COERCE)); 68 | setting.put(DYNAMIC.getElasticSearchOption(), recoverdOptionValue(configuration.getConnectorOptions(), DYNAMIC)); 69 | 70 | setting.put(CLUSTER_NAME.getElasticSearchOption(),recoverdOptionValue(configuration.getClusterOptions(), CLUSTER_NAME)); 71 | return ImmutableSettings.settingsBuilder().put(setting).build(); 72 | 73 | } 74 | 75 | /** 76 | * this recovered the option value if it is set. It not return the default value.. 77 | * 78 | * @param configuration the configuration. 79 | * @param nodeData the configuration options. 80 | * @return the actual value of the option. 81 | */ 82 | private static String recoverdOptionValue(Map configuration, ConfigurationOptions nodeData) { 83 | String option; 84 | if (configuration.containsKey(nodeData.getManifestOption())) { 85 | option = configuration.get(nodeData.getManifestOption()); 86 | } else { 87 | option = nodeData.getDefaultValue()[0]; 88 | } 89 | return option; 90 | } 91 | 92 | /** 93 | * Gets the transport address. 94 | * 95 | * @param config the configuration options. 96 | * @return the transport address 97 | */ 98 | public static TransportAddress[] getTransportAddress(ConnectorClusterConfig config) throws ExecutionException{ 99 | 100 | String[] hosts = PropertyValueRecovered.recoveredValueASArray(String.class, config.getClusterOptions().get(HOST.getManifestOption())); 101 | String[] ports = PropertyValueRecovered.recoveredValueASArray(String.class, config.getClusterOptions().get(PORT.getManifestOption())); 102 | TransportAddress[] transportAddresses = new TransportAddress[hosts.length]; 103 | 104 | for (int i = 0; i < hosts.length; i++) { 105 | transportAddresses[i] = new InetSocketTransportAddress(hosts[i], Integer.decode(ports[i])); 106 | } 107 | 108 | return transportAddresses; 109 | 110 | } 111 | } -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/connection/ElasticSearchConnectionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.connection; 20 | 21 | import com.stratio.connector.commons.TimerJ; 22 | import com.stratio.connector.commons.connection.Connection; 23 | import com.stratio.connector.commons.connection.ConnectionHandler; 24 | import com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions; 25 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 26 | import com.stratio.crossdata.common.connector.IConfiguration; 27 | import com.stratio.crossdata.common.exceptions.ConnectionException; 28 | import com.stratio.crossdata.common.exceptions.ExecutionException; 29 | import com.stratio.crossdata.common.security.ICredentials; 30 | 31 | /** 32 | * This class represents a elasticsearchs connetions handler. 33 | * Created by jmgomez on 28/08/14. 34 | */ 35 | public class ElasticSearchConnectionHandler extends ConnectionHandler { 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param configuration the configuration. 41 | */ 42 | public ElasticSearchConnectionHandler(IConfiguration configuration) { 43 | super(configuration); 44 | } 45 | 46 | /** 47 | * This method creates a elasticsearch connection. 48 | * 49 | * @param iCredentials the credentials to connect with the database. 50 | * @param connectorClusterConfig the cluster configuration. 51 | * @throws ConnectionException if the connection is not established. 52 | * @return a elasticsearch connection. 53 | */ 54 | @Override 55 | @TimerJ 56 | protected Connection createNativeConnection(ICredentials iCredentials, 57 | ConnectorClusterConfig connectorClusterConfig) throws ConnectionException { 58 | Connection connection; 59 | if (isNodeClient(connectorClusterConfig)) { 60 | connection = new NodeConnection(iCredentials, connectorClusterConfig); 61 | } 62 | else { 63 | try {connection = new TransportConnection(iCredentials, connectorClusterConfig);} 64 | catch (ExecutionException exception){ 65 | throw new ConnectionException("The connection could not be established", exception); 66 | } 67 | } 68 | if (!connection.isConnected()) { 69 | throw new ConnectionException("The connection could not be established");} 70 | return connection; 71 | } 72 | 73 | /** 74 | * Return true if the config says that the connection is nodeClient. false in other case. 75 | * 76 | * @param config the configuration. 77 | * @return true if is configure to be a node connection. False in other case. 78 | */ 79 | @TimerJ 80 | private boolean isNodeClient(ConnectorClusterConfig config) { 81 | return Boolean.parseBoolean(config.getConnectorOptions().get(ConfigurationOptions.NODE_TYPE.getManifestOption())); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/connection/NodeConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.connection; 20 | 21 | import static org.elasticsearch.node.NodeBuilder.nodeBuilder; 22 | 23 | import com.stratio.connector.commons.TimerJ; 24 | import org.elasticsearch.client.Client; 25 | import org.elasticsearch.node.Node; 26 | import org.elasticsearch.node.NodeBuilder; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | import com.stratio.connector.commons.connection.Connection; 31 | import com.stratio.connector.elasticsearch.core.configuration.ElasticsearchClientConfiguration; 32 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 33 | import com.stratio.crossdata.common.security.ICredentials; 34 | 35 | /** 36 | * This class represents a logic connection. 37 | * Created by jmgomez on 28/08/14. 38 | */ 39 | public class NodeConnection extends Connection { 40 | 41 | /** 42 | * The Log. 43 | */ 44 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 45 | 46 | /** 47 | * The Elasticsearch client. 48 | */ 49 | private Client elasticClient = null; 50 | 51 | /** 52 | * The elasticsearch node connection. 53 | */ 54 | private Node node = null; 55 | 56 | 57 | /** 58 | * Store the connection name. 59 | */ 60 | private String connectionName; 61 | 62 | /** 63 | * Constructor. 64 | * 65 | * @param credentials the credentials. 66 | * @param config The cluster configuration. 67 | */ 68 | public NodeConnection(ICredentials credentials, ConnectorClusterConfig config) { 69 | NodeBuilder nodeBuilder = nodeBuilder(); 70 | 71 | node = nodeBuilder.settings(ElasticsearchClientConfiguration.getSettings(config)).node(); 72 | elasticClient = node.client(); 73 | 74 | connectionName = config.getName().getName(); 75 | logger.info("Elasticsearch Node connection established "); 76 | 77 | } 78 | 79 | /** 80 | * Close the connection. 81 | */ 82 | @TimerJ 83 | public void close() { 84 | if (node != null) { 85 | node.close(); 86 | node = null; 87 | elasticClient = null; 88 | logger.info("ElasticSearch connection [" + connectionName + "] close"); 89 | } 90 | 91 | } 92 | 93 | /** 94 | * Retun the connection status. 95 | * 96 | * @return true if the connection is open. False in other case. 97 | */ 98 | @Override 99 | @TimerJ 100 | public boolean isConnected() { 101 | return (node!=null && !node.isClosed()); 102 | } 103 | 104 | /** 105 | * Return the native connection. 106 | * 107 | * @return the native connection. 108 | */ 109 | @Override 110 | @TimerJ 111 | public Client getNativeConnection() { 112 | return elasticClient; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/connection/TransportConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.connection; 20 | 21 | import com.stratio.connector.commons.TimerJ; 22 | import com.stratio.crossdata.common.exceptions.ExecutionException; 23 | import org.elasticsearch.client.Client; 24 | import org.elasticsearch.client.transport.TransportClient; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import com.stratio.connector.commons.connection.Connection; 29 | import com.stratio.connector.elasticsearch.core.configuration.ElasticsearchClientConfiguration; 30 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 31 | import com.stratio.crossdata.common.security.ICredentials; 32 | 33 | /** 34 | * This class represents a logic connection. 35 | * Created by jmgomez on 28/08/14. 36 | */ 37 | public class TransportConnection extends Connection { 38 | 39 | /** 40 | * The Log. 41 | */ 42 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 43 | 44 | /** 45 | * The Elasticsearch client. 46 | */ 47 | private Client elasticClient = null; 48 | 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param credentiasl the credentials. 54 | * @param config The cluster configuration. 55 | */ 56 | public TransportConnection(ICredentials credentiasl, ConnectorClusterConfig config) throws ExecutionException { 57 | 58 | elasticClient = new TransportClient(ElasticsearchClientConfiguration.getSettings(config)) 59 | .addTransportAddresses(ElasticsearchClientConfiguration.getTransportAddress(config)); 60 | logger.info("Elasticsearch Transport connection established "); 61 | 62 | 63 | } 64 | 65 | /** 66 | * Close the connection. 67 | */ 68 | @TimerJ 69 | public void close() { 70 | if (elasticClient != null) { 71 | elasticClient.close(); 72 | 73 | elasticClient = null; 74 | 75 | } 76 | 77 | } 78 | 79 | /** 80 | * Return the connection status. 81 | * 82 | * @return true if the connection is open. False in other case. 83 | */ 84 | @Override 85 | @TimerJ 86 | public boolean isConnected() { 87 | 88 | return (elasticClient!=null && !((TransportClient)elasticClient).connectedNodes().isEmpty()); 89 | 90 | 91 | } 92 | 93 | /** 94 | * Return the native connection. 95 | * 96 | * @return the native connection. 97 | */ 98 | @Override 99 | @TimerJ 100 | public Client getNativeConnection() { 101 | return elasticClient; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/ElasticsearchQueryEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine; 20 | 21 | import com.stratio.connector.commons.TimerJ; 22 | import org.elasticsearch.action.ActionRequestBuilder; 23 | import org.elasticsearch.action.search.SearchRequestBuilder; 24 | import org.elasticsearch.client.Client; 25 | 26 | import com.stratio.connector.commons.connection.Connection; 27 | import com.stratio.connector.commons.connection.ConnectionHandler; 28 | import com.stratio.connector.commons.engine.SingleProjectQueryEngine; 29 | import com.stratio.connector.commons.engine.query.ProjectParsed; 30 | import com.stratio.connector.elasticsearch.core.engine.query.ConnectorQueryBuilder; 31 | import com.stratio.connector.elasticsearch.core.engine.query.ConnectorQueryExecutor; 32 | import com.stratio.connector.elasticsearch.core.engine.query.ESProjectParsedValidator; 33 | import com.stratio.crossdata.common.connector.IResultHandler; 34 | import com.stratio.crossdata.common.exceptions.ConnectorException; 35 | import com.stratio.crossdata.common.exceptions.ExecutionException; 36 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 37 | import com.stratio.crossdata.common.logicalplan.LogicalWorkflow; 38 | import com.stratio.crossdata.common.logicalplan.Project; 39 | import com.stratio.crossdata.common.result.QueryResult; 40 | 41 | /** 42 | * This class is the responsible of manage the ElasticSearchMetadata. 43 | */ 44 | public class ElasticsearchQueryEngine extends SingleProjectQueryEngine { 45 | 46 | private ConnectorQueryBuilder queryBuilder = new ConnectorQueryBuilder(); 47 | private ConnectorQueryExecutor queryExecutor = new ConnectorQueryExecutor(); 48 | 49 | /** 50 | * Instantiates a new elasticsearch query engine. 51 | * 52 | * @param connectionHandler the connection handler 53 | */ 54 | public ElasticsearchQueryEngine(ConnectionHandler connectionHandler) { 55 | 56 | super(connectionHandler); 57 | 58 | } 59 | 60 | @Override 61 | @TimerJ 62 | protected void pagedExecute(String queryId, Project project, Connection connection, IResultHandler resultHandler) throws ConnectorException { 63 | throw new UnsupportedException("Not supported"); 64 | } 65 | 66 | @Override 67 | @TimerJ 68 | protected void asyncExecute(String queryId, Project project, Connection connection, IResultHandler resultHandler) throws ConnectorException { 69 | throw new UnsupportedException("Not supported"); 70 | } 71 | 72 | @Override 73 | @TimerJ 74 | protected QueryResult execute(Project project, Connection connection) throws ConnectorException { 75 | 76 | Client elasticClient = connection.getNativeConnection(); 77 | ProjectParsed projectParsed = new ProjectParsed(project, new ESProjectParsedValidator()); 78 | SearchRequestBuilder requestBuilder = (SearchRequestBuilder) queryBuilder.buildQuery(elasticClient, projectParsed); 79 | 80 | return queryExecutor.executeQuery(elasticClient, requestBuilder, projectParsed); 81 | } 82 | 83 | 84 | @Override 85 | @TimerJ 86 | public void stop(String queryId) throws UnsupportedException { 87 | throw new UnsupportedException("Not supported"); 88 | 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/AddColumnHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | import java.io.IOException; 22 | 23 | import org.elasticsearch.client.Client; 24 | import org.elasticsearch.common.xcontent.XContentBuilder; 25 | 26 | import com.stratio.connector.elasticsearch.core.engine.utils.ContentBuilderCreator; 27 | import com.stratio.crossdata.common.data.AlterOptions; 28 | import com.stratio.crossdata.common.data.TableName; 29 | import com.stratio.crossdata.common.exceptions.ExecutionException; 30 | 31 | /** 32 | * This class must implements the add column to a mapping feature. Created by jmgomez on 24/11/14. 33 | */ 34 | public class AddColumnHandler implements AlterTableHandler { 35 | 36 | /** 37 | * The alter options. 38 | */ 39 | private final AlterOptions alterOptions; 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param alterOptions 45 | * the alter option- 46 | */ 47 | public AddColumnHandler(AlterOptions alterOptions) { 48 | this.alterOptions = alterOptions; 49 | } 50 | 51 | /** 52 | * Execute the add column in a mapping. 53 | * 54 | * @param tableName 55 | * the table name. 56 | * @param connection 57 | * the connection. 58 | * @throws ExecutionException 59 | * if an error happens. 60 | */ 61 | @Override 62 | public void execute(TableName tableName, Client connection) throws ExecutionException { 63 | 64 | try { 65 | ContentBuilderCreator contentBuilderCreator = new ContentBuilderCreator(); 66 | XContentBuilder source = null; 67 | source = contentBuilderCreator.addColumn(alterOptions.getColumnMetadata()); 68 | connection.admin().indices().preparePutMapping(tableName.getCatalogName().getName()) 69 | .setType(tableName.getName()).setSource(source).execute().actionGet(); 70 | 71 | } catch (IOException e) { 72 | throw new ExecutionException("Error when aerospaike is adding a column in a mapping", e); 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/AlterTableFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | import com.stratio.crossdata.common.data.AlterOptions; 22 | import com.stratio.crossdata.common.exceptions.ExecutionException; 23 | 24 | /** 25 | * This class must created a object to alter a table. Created by jmgomez on 24/11/14. 26 | */ 27 | public final class AlterTableFactory { 28 | 29 | /** 30 | * The constructor. 31 | */ 32 | private AlterTableFactory() { 33 | 34 | } 35 | 36 | /** 37 | * Create the correct alter table handler. 38 | * 39 | * @param alterOptions 40 | * the alter options. 41 | * @return the correct alter table handler. 42 | * @throws ExecutionException 43 | * if the operation is not supported. 44 | */ 45 | public static AlterTableHandler createHandler(AlterOptions alterOptions) throws ExecutionException { 46 | AlterTableHandler handler; 47 | switch (alterOptions.getOption()) { 48 | case ADD_COLUMN: 49 | handler = new AddColumnHandler(alterOptions); 50 | break; 51 | default: 52 | throw new ExecutionException("The altar table operation " + alterOptions.getOption().name() + " " 53 | + "is not supporting"); 54 | } 55 | return handler; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/AlterTableHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | import org.elasticsearch.client.Client; 22 | 23 | import com.stratio.crossdata.common.data.TableName; 24 | import com.stratio.crossdata.common.exceptions.ExecutionException; 25 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 26 | 27 | /** 28 | * This interface must to be implemented for the class witch implement alter table features. 29 | * Created by jmgomez on 24/11/14. 30 | */ 31 | public interface AlterTableHandler { 32 | /** 33 | * @param tableName 34 | * @param connection 35 | * @throws UnsupportedException 36 | * @throws ExecutionException 37 | */ 38 | void execute(TableName tableName, Client connection) throws UnsupportedException, ExecutionException; 39 | } 40 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/ESIndexType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | /** 22 | * This class provide support to ES index. 23 | * Created by jmgomez on 21/11/14. 24 | */ 25 | public enum ESIndexType { 26 | /** 27 | * No Index. 28 | */ 29 | NO("no"), 30 | /** 31 | * Analyzed Index. 32 | */ 33 | ANALYZED("analyzed"), 34 | /** 35 | * Not analized index. 36 | */ 37 | NOT_ANALYZED("not_analyzed"); 38 | 39 | /** 40 | * The code. 41 | */ 42 | private final String code; 43 | 44 | /** 45 | * Cosntructor. 46 | * 47 | * @param code the code. 48 | */ 49 | ESIndexType(String code) { 50 | this.code = code; 51 | } 52 | 53 | /** 54 | * Return the default index value. 55 | * 56 | * @return the default index value. 57 | */ 58 | public static ESIndexType getDefault() { 59 | return ANALYZED; 60 | } 61 | 62 | /** 63 | * Return Index code. 64 | * 65 | * @return the index code. 66 | */ 67 | public String getCode() { 68 | return code; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/metadata/MetadataCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import com.stratio.connector.commons.engine.query.ProjectParsed; 26 | import com.stratio.crossdata.common.logicalplan.Select; 27 | import com.stratio.crossdata.common.metadata.ColumnMetadata; 28 | import com.stratio.crossdata.common.statements.structures.Selector; 29 | 30 | /** 31 | * The responsibility of this class is crete the metadata. 32 | * Created by jmgomez on 15/10/14. 33 | */ 34 | public class MetadataCreator { 35 | 36 | /** 37 | * This method creates the column metadata. 38 | * 39 | * @param queryData the queryData object. 40 | * @return the list with the column metadata. 41 | */ 42 | public List createColumnMetadata(ProjectParsed queryData) { 43 | 44 | List retunColumnMetadata = new ArrayList<>(); 45 | 46 | Select select = queryData.getSelect(); 47 | 48 | Map columnAliasMap = select.getColumnMap(); 49 | for (Map.Entry columnAliasName : columnAliasMap.entrySet()) { 50 | ColumnMetadata columnMetadata = new ColumnMetadata(columnAliasName.getKey().getColumnName(), null, 51 | select.getTypeMapFromColumnName().get(columnAliasName.getKey())); 52 | 53 | columnMetadata.getName().setAlias(columnAliasName.getValue()); 54 | retunColumnMetadata.add(columnMetadata); 55 | } 56 | 57 | return retunColumnMetadata; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/ConnectorQueryData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Collection; 23 | 24 | import com.stratio.crossdata.common.logicalplan.Filter; 25 | import com.stratio.crossdata.common.logicalplan.Limit; 26 | import com.stratio.crossdata.common.logicalplan.Project; 27 | import com.stratio.crossdata.common.logicalplan.Select; 28 | 29 | /** 30 | * This class is a representation of a ElasticSearch query. 31 | *

32 | *

33 | * Created by jmgomez on 15/09/14. 34 | */ 35 | public class ConnectorQueryData { 36 | 37 | /** 38 | * The projection. 39 | */ 40 | private Project projection = null; 41 | 42 | /** 43 | * The filters. 44 | */ 45 | private Collection filterList = new ArrayList<>(); 46 | /** 47 | * The matchList. 48 | */ 49 | private Collection matchList = new ArrayList<>(); 50 | 51 | /** 52 | * The select. 53 | */ 54 | private Select select; 55 | /** 56 | * The limit. 57 | */ 58 | private Limit limit; 59 | 60 | /** 61 | * Add a filter. 62 | * 63 | * @param filter the filter. 64 | */ 65 | public void addFilter(Filter filter) { 66 | 67 | filterList.add(filter); 68 | } 69 | 70 | /** 71 | * This method ask query if has projection. 72 | * 73 | * @return true if the query has projection. False in other case. 74 | */ 75 | public boolean hasProjection() { 76 | 77 | return projection != null; 78 | } 79 | 80 | /** 81 | * Get the projection. 82 | * 83 | * @return the projection, 84 | */ 85 | public Project getProjection() { 86 | 87 | return projection; 88 | } 89 | 90 | /** 91 | * Set the projection. 92 | * 93 | * @param projection the projection. 94 | */ 95 | public void setProjection(Project projection) { 96 | 97 | this.projection = projection; 98 | } 99 | 100 | /** 101 | * Get the filter. 102 | * 103 | * @return the filter. 104 | */ 105 | public Collection getFilter() { 106 | return filterList; 107 | } 108 | 109 | /** 110 | * Add filter to the matchList. 111 | * 112 | * @param filter the filter to add. 113 | */ 114 | public void addMatch(Filter filter) { 115 | 116 | matchList.add(filter); 117 | } 118 | 119 | /** 120 | * Return The matchList. 121 | * 122 | * @return the matchList 123 | */ 124 | public Collection getMatchList() { 125 | return matchList; 126 | } 127 | 128 | /** 129 | * This method ask query if has filter list. 130 | * 131 | * @return true if the query has filter list. False in other case. 132 | */ 133 | public boolean hasFilterList() { 134 | return !filterList.isEmpty(); 135 | } 136 | 137 | /** 138 | * return the select. 139 | * 140 | * @return the select. 141 | */ 142 | public Select getSelect() { 143 | return select; 144 | } 145 | 146 | /** 147 | * Add a select type. 148 | * 149 | * @param select the select. 150 | */ 151 | public void setSelect(Select select) { 152 | this.select = select; 153 | 154 | } 155 | 156 | /** 157 | * Return the limit. 158 | * 159 | * @return the limit. 160 | */ 161 | public Limit getLimit() { 162 | return limit; 163 | } 164 | 165 | /** 166 | * set the limit. 167 | * 168 | * @param limit the limit. 169 | */ 170 | public void setLimit(Limit limit) { 171 | this.limit = limit; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/ConnectorQueryParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 23 | import com.stratio.crossdata.common.logicalplan.Filter; 24 | import com.stratio.crossdata.common.logicalplan.Limit; 25 | import com.stratio.crossdata.common.logicalplan.LogicalStep; 26 | import com.stratio.crossdata.common.logicalplan.Project; 27 | import com.stratio.crossdata.common.logicalplan.Select; 28 | import com.stratio.crossdata.common.statements.structures.Operator; 29 | 30 | /** 31 | * The responsibility of this class is parser he LogicalWorkFlow to a QueryData. Created by jmgomez on 15/09/14. 32 | */ 33 | public class ConnectorQueryParser { 34 | 35 | /** 36 | * this method transfor a logical workflow to a queryData. 37 | * 38 | * @param logicalWorkFlow 39 | * the logical workflow. 40 | * @return the queryData. 41 | * @throws UnsupportedException 42 | * if the logicalworkflow contains unsupported operations. 43 | * @throws ExecutionException 44 | * if the execution fails. 45 | */ 46 | public ConnectorQueryData transformLogicalWorkFlow(Project logicalWorkFlow) throws UnsupportedException, 47 | ExecutionException { 48 | 49 | ConnectorQueryData queryData = new ConnectorQueryData(); 50 | LogicalStep lStep = logicalWorkFlow; 51 | 52 | do { 53 | if (lStep instanceof Project) { 54 | if (!queryData.hasProjection()) { 55 | queryData.setProjection((Project) lStep); 56 | } else { 57 | throw new ExecutionException(" # Project > 1"); 58 | } 59 | } else if (lStep instanceof Filter) { 60 | 61 | Filter step = (Filter) lStep; 62 | if (Operator.MATCH == step.getRelation().getOperator()) { 63 | queryData.addMatch((Filter) lStep); 64 | } else { 65 | queryData.addFilter((Filter) lStep); 66 | } 67 | } else if (lStep instanceof Select) { 68 | queryData.setSelect((Select) lStep); 69 | 70 | } else if (lStep instanceof Limit) { 71 | queryData.setLimit((Limit) lStep); 72 | } else { 73 | throw new UnsupportedException("LogicalStep [" + lStep.getClass().getCanonicalName() + " not supported"); 74 | } 75 | 76 | lStep = lStep.getNextStep(); 77 | 78 | } while (lStep != null); 79 | 80 | checkSupportedQuery(queryData); 81 | 82 | return queryData; 83 | } 84 | 85 | /** 86 | * Check if the queryData is supported. 87 | * 88 | * @param queryData 89 | * the qiery data. 90 | * @throws ExecutionException 91 | * if there is no select. 92 | */ 93 | private void checkSupportedQuery(ConnectorQueryData queryData) throws ExecutionException { 94 | if (queryData.getSelect() == null) { 95 | throw new ExecutionException("no select found"); 96 | } 97 | 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/ESProjectParsedValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query; 20 | 21 | import com.stratio.connector.commons.engine.query.ProjectParsed; 22 | import com.stratio.connector.commons.engine.query.ProjectValidator; 23 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 24 | 25 | /** 26 | * Created by jmgomez on 17/12/14. 27 | */ 28 | public class ESProjectParsedValidator implements ProjectValidator { 29 | 30 | /** 31 | * This method validate the project parsed to ElasticSearch. 32 | * 33 | * @param projectParsed 34 | * the project parsed. 35 | * @throws UnsupportedException 36 | * if a logicalStep is not supported 37 | * 38 | */ 39 | @Override 40 | public void validate(ProjectParsed projectParsed) throws UnsupportedException { 41 | if (projectParsed.getWindow() != null) { 42 | throw new UnsupportedException("ElasticSearch don't support Window Operation"); 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/ESFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 23 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 24 | import com.stratio.crossdata.common.statements.structures.Selector; 25 | import org.elasticsearch.index.query.QueryBuilder; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * Encapsulate an Elastic Search "Function", The child of this abstract class will instance the 32 | * specific QueryBuilder that represents the filter required. 33 | */ 34 | public abstract class ESFunction { 35 | 36 | public static final String CONTAINS = "contains"; 37 | public static final String MATCH_PHRASE = "match_phrase"; 38 | public static final String MULTI_MATCH = "multi_match"; 39 | public static final String MATCH_PREFIX = "match_prefix"; 40 | public static final String MULTI_MATCH_FUZZY = "multi_match_fuzzy"; 41 | public static final String FUZZY = "fuzzy"; 42 | 43 | 44 | /** 45 | * Function Name 46 | */ 47 | private String name; 48 | 49 | /** 50 | * The function parameters. 51 | */ 52 | private List parameters; 53 | 54 | /** 55 | * Default constructor. 56 | * 57 | * @param name Function Name 58 | * @param paramareters function parameters. 59 | */ 60 | protected ESFunction(String name, List paramareters) { 61 | this.parameters = paramareters; 62 | this.name = name; 63 | } 64 | 65 | public List getParameters() { 66 | return parameters; 67 | } 68 | 69 | public String getName() { 70 | return name; 71 | } 72 | 73 | /** 74 | * Build a {@link org.elasticsearch.index.query.QueryBuilder} that satisfy this function. 75 | * 76 | * @return 77 | */ 78 | public abstract QueryBuilder buildQuery() throws ExecutionException; 79 | 80 | 81 | /** 82 | * Builds a ESFunction using the FunctionRelation specification.cd 83 | * @param function 84 | * @return A ESFunction child. 85 | * @throws UnsupportedException is the FunctionRelation isn't supported. 86 | */ 87 | public static ESFunction build(FunctionRelation function) throws UnsupportedException { 88 | List parameters = new ArrayList(); 89 | parameters.addAll(function.getFunctionSelectors()); 90 | 91 | switch(function.getFunctionName()){ 92 | case CONTAINS: 93 | return new Match(parameters); 94 | case MATCH_PHRASE: 95 | return new MatchPhrase(parameters); 96 | case MULTI_MATCH: 97 | return new MultiMatch(parameters); 98 | case MATCH_PREFIX: 99 | return new MatchPrefix(parameters); 100 | case MULTI_MATCH_FUZZY: 101 | return new MultiMatchFuzzy(parameters); 102 | case FUZZY: 103 | return new Fuzzy(parameters); 104 | default: 105 | throw new UnsupportedException("The function [" + function.getFunctionName() + "] is not supported"); 106 | } 107 | } 108 | 109 | /** 110 | * Checks function signature 111 | * 112 | * @param functionName function name 113 | * @param checkEmpty flag that indicates if empty values are allowed 114 | * @param expectedParameters expected number of parameters 115 | * @param expectedSignature expected function signature 116 | * @throws ExecutionException 117 | */ 118 | public void validateFunctionSignature (String functionName, boolean checkEmpty, int expectedParameters, String expectedSignature) 119 | throws ExecutionException { 120 | 121 | if (null == parameters || parameters.size() != expectedParameters){ 122 | throw new ExecutionException("Wrong number of parameters for \"" + functionName + "\" function. " + 123 | "Expected signature: " + expectedSignature + "."); 124 | } 125 | if (checkEmpty){ 126 | for (Selector parameter : parameters) { 127 | if (null == parameter || parameter.getStringValue().trim().isEmpty()){ 128 | throw new ExecutionException("Every parameter in \"" + functionName + "\" function must have a non empty value."); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/Fuzzy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 23 | import com.stratio.crossdata.common.statements.structures.Selector; 24 | import com.stratio.crossdata.common.statements.structures.StringSelector; 25 | import org.elasticsearch.common.unit.Fuzziness; 26 | import org.elasticsearch.index.query.QueryBuilder; 27 | import org.elasticsearch.index.query.QueryBuilders; 28 | 29 | import java.util.List; 30 | 31 | public class Fuzzy extends ESFunction{ 32 | 33 | private final String FUNCTION_NAME = "fuzzy"; 34 | private final String EXPECTED_SIGNATURE = "fuzzy (fields, value, fuzziness)"; 35 | private final int EXPECTED_PARAMETERS = 3; 36 | 37 | protected Fuzzy(List parameters) { 38 | super(ESFunction.FUZZY, parameters); 39 | } 40 | 41 | @Override 42 | public QueryBuilder buildQuery() throws ExecutionException { 43 | 44 | // Checks function signature 45 | validateFunctionSignature(FUNCTION_NAME, true, EXPECTED_PARAMETERS, EXPECTED_SIGNATURE); 46 | 47 | // Retrieves function parameters 48 | 49 | // Retrieves the string to be seached 50 | String value = getParameters().get(1).getStringValue(); 51 | 52 | // Retrieves the fuzziness value 53 | String fuzziness = getParameters().get(2).getStringValue(); 54 | 55 | // Retrieves the fields to be searched in 56 | String fields = ""; 57 | 58 | // If first parameter is a column its name is set as the search field 59 | if (getParameters().get(0) instanceof ColumnSelector ){ 60 | fields = ((ColumnSelector) getParameters().get(0)).getColumnName().getName(); 61 | } 62 | // Otherwise the received value is treated as the search fields string 63 | else { 64 | fields = getParameters().get(0).getStringValue(); 65 | } 66 | 67 | // Once the search fields string is retrieved it is checked if more than one field is queried so we could build a match or multi match query 68 | if (fields.split("\\s+").length > 1){ 69 | return QueryBuilders.multiMatchQuery(value, fields.split("\\s+")).fuzziness(fuzziness); 70 | } 71 | else { 72 | return QueryBuilders.fuzzyQuery(fields, value).fuzziness(Fuzziness.build(fuzziness)); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/Match.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 23 | import com.stratio.crossdata.common.statements.structures.Selector; 24 | import com.stratio.crossdata.common.statements.structures.StringSelector; 25 | import org.apache.commons.lang3.StringUtils; 26 | import org.elasticsearch.index.query.QueryBuilder; 27 | import org.elasticsearch.index.query.QueryBuilders; 28 | 29 | import java.util.List; 30 | 31 | public class Match extends ESFunction{ 32 | 33 | private final String FUNCTION_NAME = "contains"; 34 | private final String EXPECTED_SIGNATURE = "contains (fields, value, minimumShouldMatch)"; 35 | private final int EXPECTED_PARAMETERS = 3; 36 | 37 | protected Match(List parameters) {super(ESFunction.CONTAINS, parameters);} 38 | 39 | @Override 40 | public QueryBuilder buildQuery() throws ExecutionException { 41 | 42 | // Checks function signature 43 | validateFunctionSignature(FUNCTION_NAME, true, EXPECTED_PARAMETERS, EXPECTED_SIGNATURE); 44 | 45 | // Retrieves function parameters 46 | 47 | // Retrieves the string to be seached 48 | String value = getParameters().get(1).getStringValue(); 49 | 50 | // Retrieves the minimum should match value 51 | String minimumShouldMatch = getParameters().get(2).getStringValue(); 52 | 53 | // Retrieves the fields to be searched in 54 | String fields = ""; 55 | 56 | // If first parameter is a column its name is set as the search field 57 | if (getParameters().get(0) instanceof ColumnSelector ){ 58 | fields = ((ColumnSelector) getParameters().get(0)).getColumnName().getName(); 59 | } 60 | // Otherwise the received value is treated as the search fields string 61 | else { 62 | fields = getParameters().get(0).getStringValue(); 63 | } 64 | 65 | // Once the search fields string is retrieved it is checked if more than one field is queried so we could build a match or multi match query 66 | if (fields.split("\\s+").length > 1){ 67 | return QueryBuilders.multiMatchQuery(value, fields.split("\\s+")); 68 | } 69 | else { 70 | return QueryBuilders.matchQuery(fields, value).minimumShouldMatch(minimumShouldMatch); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MatchPhrase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 23 | import com.stratio.crossdata.common.statements.structures.Selector; 24 | import org.elasticsearch.index.query.QueryBuilder; 25 | import org.elasticsearch.index.query.QueryBuilders; 26 | 27 | import java.util.List; 28 | 29 | /** 30 | * Created by lcisneros on 2/06/15. 31 | */ 32 | public class MatchPhrase extends ESFunction { 33 | 34 | private final String FUNCTION_NAME = "match_phrase"; 35 | private final String EXPECTED_SIGNATURE = "match_phrase (field, phrase)"; 36 | private final int EXPECTED_PARAMETERS = 2; 37 | 38 | protected MatchPhrase(List parameters) { 39 | super(ESFunction.MATCH_PHRASE, parameters); 40 | } 41 | 42 | @Override 43 | public QueryBuilder buildQuery() throws ExecutionException { 44 | 45 | // Checks function signature 46 | validateFunctionSignature(FUNCTION_NAME, true, EXPECTED_PARAMETERS, EXPECTED_SIGNATURE); 47 | 48 | // Retrieves function parameters 49 | 50 | // Retrieves the string to be seached 51 | String value = getParameters().get(1).getStringValue(); 52 | 53 | // Retrieves the field to be searched in 54 | String field = ""; 55 | 56 | // If first parameter is a column its name is set as the search field 57 | if (getParameters().get(0) instanceof ColumnSelector ){ 58 | field = ((ColumnSelector) getParameters().get(0)).getColumnName().getName(); 59 | } 60 | // Otherwise the received value is treated as the search fields string 61 | else { 62 | field = getParameters().get(0).getStringValue(); 63 | } 64 | 65 | // Builds the match phrase query 66 | return QueryBuilders.matchPhraseQuery(field, value); 67 | } 68 | } -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MatchPrefix.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 23 | import com.stratio.crossdata.common.statements.structures.Selector; 24 | import org.elasticsearch.index.query.QueryBuilder; 25 | import org.elasticsearch.index.query.QueryBuilders; 26 | 27 | import java.util.List; 28 | 29 | public class MatchPrefix extends ESFunction { 30 | 31 | private final String FUNCTION_NAME = "match_prefix"; 32 | private final String EXPECTED_SIGNATURE = "match_prefix (field, prefix)"; 33 | private final int EXPECTED_PARAMETERS = 2; 34 | 35 | protected MatchPrefix(List parameters) {super(ESFunction.MATCH_PREFIX, parameters);} 36 | 37 | @Override 38 | public QueryBuilder buildQuery() throws ExecutionException { 39 | 40 | // Checks function signature 41 | validateFunctionSignature(FUNCTION_NAME, true, EXPECTED_PARAMETERS, EXPECTED_SIGNATURE); 42 | 43 | // Retrieves function parameters 44 | 45 | // Retrieves the string to be seached 46 | String value = getParameters().get(1).getStringValue(); 47 | 48 | // Retrieves the field to be searched in 49 | String field = ""; 50 | 51 | // If first parameter is a column its name is set as the search field 52 | if (getParameters().get(0) instanceof ColumnSelector ){ 53 | field = ((ColumnSelector) getParameters().get(0)).getColumnName().getName(); 54 | } 55 | // Otherwise the received value is treated as the search fields string 56 | else { 57 | field = getParameters().get(0).getStringValue(); 58 | } 59 | 60 | // Builds the match phrase query 61 | return QueryBuilders.prefixQuery(field, value); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MultiMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 22 | import com.stratio.crossdata.common.statements.structures.Selector; 23 | import org.elasticsearch.index.query.QueryBuilder; 24 | import org.elasticsearch.index.query.QueryBuilders; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | public class MultiMatch extends ESFunction { 30 | 31 | protected MultiMatch(List parameters) { 32 | super(ESFunction.MULTI_MATCH, parameters); 33 | } 34 | 35 | @Override 36 | public QueryBuilder buildQuery() { 37 | 38 | String minimumShouldMatch = getParameters().get(getParameters().size() -1).getStringValue(); 39 | String value = getParameters().get(getParameters().size() -2).getStringValue(); 40 | String[] fields = new String[getParameters().size() -2]; 41 | 42 | for (int i = 0; i < getParameters().size() -2; i++){ 43 | if (getParameters().get(i) instanceof ColumnSelector){ 44 | fields[i]=((ColumnSelector) getParameters().get(i)).getColumnName().getName(); 45 | }else{ 46 | fields[i]= getParameters().get(i).getStringValue(); 47 | } 48 | } 49 | 50 | return QueryBuilders.multiMatchQuery(value, fields).minimumShouldMatch(minimumShouldMatch); 51 | } 52 | } -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MultiMatchFuzzy.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 2 | 3 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 4 | import com.stratio.crossdata.common.statements.structures.Selector; 5 | import org.elasticsearch.index.query.QueryBuilder; 6 | import org.elasticsearch.index.query.QueryBuilders; 7 | 8 | import java.util.List; 9 | 10 | 11 | public class MultiMatchFuzzy extends ESFunction { 12 | 13 | protected MultiMatchFuzzy(List parameters) { 14 | super(ESFunction.MULTI_MATCH_FUZZY, parameters); 15 | } 16 | 17 | @Override 18 | public QueryBuilder buildQuery() { 19 | 20 | String fuzziness = getParameters().get(getParameters().size() -1).getStringValue(); 21 | String value = getParameters().get(getParameters().size() -2).getStringValue(); 22 | String[] fields = new String[getParameters().size() -2]; 23 | 24 | for (int i = 0; i < getParameters().size() -2; i++){ 25 | if (getParameters().get(i) instanceof ColumnSelector){ 26 | fields[i]=((ColumnSelector) getParameters().get(i)).getColumnName().getName(); 27 | }else{ 28 | fields[i]= getParameters().get(i).getStringValue(); 29 | } 30 | } 31 | 32 | return QueryBuilders.multiMatchQuery(value, fields).fuzziness(fuzziness); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.utils; 20 | 21 | /** 22 | * A class with constants. 23 | * Created by jmgomez on 23/10/14. 24 | */ 25 | public final class Constants { 26 | 27 | /** 28 | * String representation for false. 29 | */ 30 | public static final String FALSE = "false"; 31 | /** 32 | * String representation for true. 33 | */ 34 | public static final String TRUE = "true"; 35 | 36 | /** 37 | * Constructor. 38 | */ 39 | private Constants() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/IndexRequestBuilderCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.utils; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | import org.elasticsearch.action.index.IndexRequestBuilder; 25 | import org.elasticsearch.client.Client; 26 | 27 | import com.stratio.crossdata.common.data.Cell; 28 | import com.stratio.crossdata.common.data.ColumnName; 29 | import com.stratio.crossdata.common.data.Row; 30 | import com.stratio.crossdata.common.data.TableName; 31 | import com.stratio.crossdata.common.exceptions.ExecutionException; 32 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 33 | import com.stratio.crossdata.common.metadata.TableMetadata; 34 | 35 | /** 36 | * The responsibility of this class is create a IndexRequestBuilder. Created by jmgomez on 12/09/14. 37 | */ 38 | public class IndexRequestBuilderCreator { 39 | 40 | /** 41 | * Returns an IndexRequestBuilder. 42 | * 43 | * @param targetTable 44 | * the table where the row must be inserted. 45 | * @param elasticClient 46 | * the connection to elastic search. 47 | * @param row 48 | * the row to insert. 49 | * @return the index request builder 50 | * @throws ExecutionException 51 | * if the opperation is not supported. 52 | */ 53 | public IndexRequestBuilder createIndexRequestBuilder(TableMetadata targetTable, Client elasticClient, Row row) 54 | throws ExecutionException { 55 | 56 | Map dataInsert = createInsertMap(row); 57 | String pk = createPrimaryKey(targetTable, dataInsert); 58 | IndexRequestBuilder indexRequestBuilder = createIndexRequestBuilder(elasticClient, targetTable, dataInsert, pk); 59 | 60 | return indexRequestBuilder; 61 | 62 | } 63 | 64 | /** 65 | * This method creates a indexrequestbuilder with PK. 66 | * 67 | * @param elasticClient 68 | * the connection to elastic search. 69 | * @param targetTable 70 | * the table where the row must be inserted. 71 | * @param dataInsert 72 | * the data to insert. 73 | * @param pk 74 | * the pk. 75 | * @return the index builder 76 | */ 77 | private IndexRequestBuilder createIndexRequestBuilder(Client elasticClient, TableMetadata targetTable, 78 | Map dataInsert, String pk) { 79 | IndexRequestBuilder indexRequestBuilder; 80 | 81 | String index = targetTable.getName().getCatalogName().getName(); 82 | String type = targetTable.getName().getName(); 83 | 84 | if (pk != null) { 85 | indexRequestBuilder = elasticClient.prepareIndex(index, type, pk).setSource(dataInsert); 86 | } else { 87 | indexRequestBuilder = elasticClient.prepareIndex(index, type).setSource(dataInsert); 88 | } 89 | 90 | return indexRequestBuilder; 91 | } 92 | 93 | /** 94 | * Return the table PK. 95 | * 96 | * @param targetTable 97 | * the table. 98 | * @param dataInsert 99 | * the data to insert. 100 | * @return the value of PK. Null if don't exist PK. 101 | * @throws ExecutionException 102 | * if the pk type is not supported. 103 | */ 104 | private String createPrimaryKey(TableMetadata targetTable, Map dataInsert) 105 | throws ExecutionException { 106 | String pk = null; 107 | 108 | for (Map.Entry rowName : dataInsert.entrySet()) { 109 | TableName tableName = targetTable.getName(); 110 | 111 | if (targetTable.isPK(new ColumnName(tableName.getCatalogName().getName(), tableName.getName(), rowName 112 | .getKey()))) { 113 | String tempPK = rowName.getValue().toString(); 114 | checkPkTypeSupport(pk); 115 | pk = tempPK; 116 | } 117 | } 118 | 119 | return pk; 120 | } 121 | 122 | /** 123 | * Check if the PK type is support. 124 | * 125 | * @param pk 126 | * the actual PK. 127 | * @throws UnsupportedException 128 | * if the PK is not supported. 129 | */ 130 | private void checkPkTypeSupport(String pk) throws ExecutionException { 131 | if (pk != null) { 132 | throw new ExecutionException("Only one PK is allowed"); 133 | } 134 | 135 | } 136 | 137 | /** 138 | * this method converts a ROW in a MAP. 139 | * 140 | * @param row 141 | * the row. 142 | * @return the map from the row. 143 | */ 144 | private Map createInsertMap(Row row) { 145 | Map dataInsert = new HashMap(); 146 | for (Map.Entry entry : row.getCells().entrySet()) { 147 | Object cellValue = entry.getValue().getValue(); 148 | dataInsert.put(entry.getKey(), cellValue); 149 | } 150 | 151 | return dataInsert; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/RowSorter.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.utils; 2 | 3 | import com.stratio.crossdata.common.data.Row; 4 | import com.stratio.crossdata.common.statements.structures.AliasSelector; 5 | import com.stratio.crossdata.common.statements.structures.FunctionSelector; 6 | import com.stratio.crossdata.common.statements.structures.OrderByClause; 7 | import com.stratio.crossdata.common.statements.structures.OrderDirection; 8 | 9 | import java.util.Comparator; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by lcisneros on 25/09/15. 15 | */ 16 | public class RowSorter implements Comparator { 17 | private List sortCriteria; 18 | public RowSorter(List criteria){ 19 | this.sortCriteria = criteria; 20 | } 21 | 22 | @Override 23 | public int compare(Row o1, Row o2) { 24 | Integer value1 = null; 25 | 26 | 27 | Iterator columns = sortCriteria.iterator(); 28 | 29 | while(columns.hasNext()){ 30 | OrderByClause clause = columns.next(); 31 | 32 | String fieldName = SelectorUtils.calculateAlias(clause.getSelector()); 33 | 34 | if (!o1.getCells().containsKey(fieldName)){ 35 | return 0; 36 | } 37 | 38 | Comparable o1Value = (Comparable) o1.getCell(fieldName).getValue(); 39 | Comparable o2Value = (Comparable) o2.getCell(fieldName).getValue(); 40 | if (clause.getDirection().equals(OrderDirection.ASC)) { 41 | value1 = o1Value.compareTo(o2Value); 42 | }else{ 43 | value1 = o2Value.compareTo(o1Value); 44 | } 45 | 46 | if (value1 != 0){ 47 | return value1; 48 | } 49 | } 50 | 51 | return 0; 52 | } 53 | } -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/SelectorUtils.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.utils; 2 | 3 | import com.stratio.crossdata.common.statements.structures.AliasSelector; 4 | import com.stratio.crossdata.common.statements.structures.FunctionSelector; 5 | import com.stratio.crossdata.common.statements.structures.Selector; 6 | import org.apache.commons.lang3.ArrayUtils; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * Class that includes all methods associated with query functions included in select statement 12 | * 13 | * Created by alejandro on 7/07/15. 14 | */ 15 | public class SelectorUtils { 16 | 17 | // Function names 18 | private static final String SUB_FIELD_FUNCTION = "sub_field"; 19 | 20 | 21 | /** 22 | * Retrieves the field name associated to a given selector (It may be both a basic field or a function. Functions must have their own process in order to get the 23 | * field name. If no process is defined the function name is returned as selector field name 24 | * 25 | * @param selector object defining a field or a function 26 | * @return name associated to the selector 27 | */ 28 | public static String getSelectorFieldName (Selector selector){ 29 | // If no selector is provided null is returned 30 | if (null == selector){return null;} 31 | // If the selector is a function it is processed in order to get the field name 32 | if (selector instanceof FunctionSelector){ 33 | return getFunctionSelectorFieldName((FunctionSelector) selector); 34 | } 35 | if (selector instanceof AliasSelector){ 36 | return getSelectorFieldName(((AliasSelector)selector).getReferencedSelector()); 37 | } 38 | // Otherwise the selector is a field, so its name is returned 39 | return selector.getColumnName().getName(); 40 | } 41 | 42 | /** 43 | * Method that retrieves the field name associated to the given function. Every function must have its own process to extract the field name, otherwise the function 44 | * name is returned instead. 45 | * 46 | * @param functionSelector function for which associated name is being retrieved 47 | * @return field name associated to the function or the function's name if no field name is associated to that specific function 48 | */ 49 | private static String getFunctionSelectorFieldName (FunctionSelector functionSelector){ 50 | if (SUB_FIELD_FUNCTION.equalsIgnoreCase(functionSelector.getFunctionName())){ 51 | return getSubFieldFunctionSelectorFieldName(functionSelector); 52 | } 53 | return functionSelector.getFunctionName(); 54 | } 55 | 56 | /** 57 | * Method that retrieves the name associated to sub field functions. It builds the field name by concatenating the base field (First function parameter) and the 58 | * analyzer associated to that field (Second function parameter) separated by a colon. 59 | * 60 | * @param subFieldFunctionSelector 61 | * @return 62 | */ 63 | private static String getSubFieldFunctionSelectorFieldName (FunctionSelector subFieldFunctionSelector){ 64 | // Retrieves the base field name 65 | String field = subFieldFunctionSelector.getFunctionColumns().getSelectorList().get(0).getColumnName().getName(); 66 | // Retrieves the analyzer name 67 | String subField = subFieldFunctionSelector.getFunctionColumns().getSelectorList().get(1).getStringValue(); 68 | // Builds field name 69 | return field + "." + subField; 70 | } 71 | 72 | 73 | 74 | /** 75 | * Return if the Selector is a function, and if the function name is the passed. 76 | * 77 | * @param selector 78 | * @param functionName 79 | * @return 80 | */ 81 | public static boolean isFunction(Selector selector, String... functionName) { 82 | 83 | if (!(selector instanceof FunctionSelector)) 84 | return false; 85 | 86 | FunctionSelector functionSelector = (FunctionSelector) selector; 87 | return ArrayUtils.contains(functionName, functionSelector.getFunctionName().toLowerCase().toString()); 88 | } 89 | 90 | 91 | public static boolean hasFunction(Map columnMetadata, String... functionName) { 92 | 93 | for (Selector selector : columnMetadata.keySet()) { 94 | if (isFunction(selector, functionName)) { 95 | return true; 96 | } 97 | } 98 | 99 | return false; 100 | } 101 | 102 | public static FunctionSelector getFunctionSelector(Map columnMetadata, String functionName) { 103 | 104 | for (Selector selector : columnMetadata.keySet()) { 105 | if (isFunction(selector, functionName)) { 106 | return (FunctionSelector) selector; 107 | } 108 | } 109 | 110 | return null; 111 | } 112 | 113 | public static String calculateSubFieldName(Selector selector) { 114 | FunctionSelector functionSelector = (FunctionSelector) selector; 115 | String field = functionSelector.getFunctionColumns().getSelectorList().get(0).getColumnName().getName(); 116 | String subField = functionSelector.getFunctionColumns().getSelectorList().get(1).getStringValue(); 117 | return field +"."+subField; 118 | } 119 | 120 | 121 | public static String calculateAlias(Selector selector){ 122 | String fieldName =selector.getAlias(); 123 | 124 | if (fieldName == null && selector instanceof FunctionSelector){ 125 | return ((FunctionSelector) selector).getAlias(); 126 | }else if (fieldName == null && selector instanceof AliasSelector){ 127 | return ((AliasSelector) selector).getReferencedSelector().getAlias(); 128 | }else if (fieldName == null){ 129 | return selector.getColumnName().getName(); 130 | } 131 | 132 | return fieldName; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/java/com/stratio/connector/elasticsearch/core/engine/utils/TypeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.utils; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.metadata.ColumnType; 23 | import com.stratio.crossdata.common.metadata.DataType; 24 | 25 | /** 26 | * Created by jmgomez on 24/11/14. 27 | */ 28 | public final class TypeConverter { 29 | 30 | public static final String ES_LONG = "long"; 31 | /** 32 | * The elasticsearch boolean name. 33 | */ 34 | public static final String ES_BOOLEAN = "boolean"; 35 | /** 36 | * The elasticsearch double name. 37 | */ 38 | public static final String ES_DOUBLE = "double"; 39 | /** 40 | * The elasticsearch float name. 41 | */ 42 | public static final String ES_FLOAT = "float"; 43 | /** 44 | * The elasticsearch integer name. 45 | */ 46 | public static final String ES_INTEGER = "integer"; 47 | /** 48 | * The elasticsearch string name. 49 | */ 50 | public static final String ES_STRING = "string"; 51 | 52 | /** 53 | * The elasticsearch string name. 54 | */ 55 | public static final String ES_DATE = "date"; 56 | 57 | /** 58 | * Constructor. 59 | */ 60 | private TypeConverter() { 61 | } 62 | 63 | /** 64 | * This method translates the crossdata columnType to ElasticSearch type. 65 | * 66 | * @param columnType 67 | * the crossdata column type. 68 | * @return the ElasticSearch columnType. 69 | * @throws ExecutionException 70 | * if the type is not supported. 71 | */ 72 | public static String convert(ColumnType columnType) throws ExecutionException { 73 | 74 | String type; 75 | if (columnType.getDataType() == DataType.BIGINT){ 76 | type = ES_LONG; 77 | } else if (columnType.getDataType() == DataType.BOOLEAN) { 78 | type = ES_BOOLEAN; 79 | } else if (columnType.getDataType() == DataType.DOUBLE) { 80 | type = ES_DOUBLE; 81 | } else if (columnType.getDataType() == DataType.FLOAT) { 82 | type = ES_FLOAT; 83 | } else if (columnType.getDataType() == DataType.INT) { 84 | type = ES_INTEGER; 85 | } else if (columnType.getDataType() == DataType.TEXT) { 86 | type = ES_STRING; 87 | } else if (columnType.getDataType() == DataType.VARCHAR) { 88 | type = ES_STRING; 89 | } else if (columnType.getDataType() == DataType.NATIVE && columnType.getODBCType().equals("date")) { 90 | type = columnType.getODBCType(); 91 | }else if (columnType.getDataType() == DataType.LIST) { 92 | type = convert(columnType.getDbInnerType()); 93 | } else { 94 | throw new ExecutionException("The type [" + columnType + "] is not supported in ElasticSearch"); 95 | } 96 | return type; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/template/ElasticSearchConnector: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: stratio-connector-elasticsearch 4 | # Required-Start: $local_fs $network $named $time $syslog 5 | # Required-Stop: $local_fs $network $named $time $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Description: mongo connector script 9 | ### END INIT INFO 10 | #export JAVA_HOME=/usr/java/default 11 | #export JAVA=$JAVA_HOME/bin/java 12 | RUNAS=root 13 | 14 | PIDPATH=/var/run/sds/ 15 | PIDNAME=stratio-connector-elasticsearch.pid 16 | PIDFILE=$PIDPATH$PIDNAME 17 | LOGFILE=/var/log/sds/connectors/elasticsearch/stratio-connector-elasticsearch.log 18 | start() { 19 | if [ ! -d "$PIDPATH" ]; then 20 | mkdir $PIDPATH 21 | fi 22 | 23 | if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then 24 | echo 'Service already running' >&2 25 | return 1 26 | fi 27 | echo 'Starting service…' >&2 28 | cd /opt/sds/connectors/elasticsearch/ 29 | 30 | nohup bin/stratio-connector-elasticsearch start > $LOGFILE & echo $! $RUNAS > $PIDFILE 31 | echo 'Service started' 32 | } 33 | 34 | stop() { 35 | # if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 36 | # echo 'Service not running' >&2 37 | # return 1 38 | # fi 39 | # echo 'Stopping service…' >&2 40 | # kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 41 | # echo 'Service stopped' >&2 42 | cd /opt/sds/connectors/elasticsearch/ 43 | nohup bin/stratio-connector-elasticsearch stop > $LOGFILE 44 | echo 'Service stopped' 45 | } 46 | 47 | uninstall() { 48 | echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " 49 | local SURE 50 | read SURE 51 | if [ "$SURE" = "yes" ]; then 52 | stop 53 | rm -f "$PIDFILE" 54 | echo "Notice: log file is not be removed: '$LOGFILE'" >&2 55 | update-rc.d -f remove 56 | rm -fv "$0" 57 | fi 58 | } 59 | 60 | case "$1" in 61 | start) 62 | start 63 | ;; 64 | stop) 65 | stop 66 | ;; 67 | uninstall) 68 | uninstall 69 | ;; 70 | retart) 71 | stop 72 | start 73 | ;; 74 | *) 75 | echo "Usage: $0 start|stop|restart|uninstall" 76 | exit 1 77 | 78 | esac 79 | 80 | exit 0 81 | 82 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/files_and_dirs/DEBIAN/conffiles: -------------------------------------------------------------------------------- 1 | /etc/default/connectors/elasticsearch 2 | /etc/sds/connectors/elasticsearch/connector-application.conf 3 | /etc/sds/connectors/elasticsearch/log.properties 4 | /etc/sds/connectors/elasticsearch/connector-reference.conf 5 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/files_and_dirs/DEBIAN/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Copyright: 2014, Stratio, Inc. All rights reserved 3 | License: Stratio License available at http://www.stratio.com/licenses 4 | Files: * 5 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/files_and_dirs/etc/default/elasticsearch_connector: -------------------------------------------------------------------------------- 1 | export ELASTICSEARCH_CONNECTOR_CONF="/etc/sds/stratio-connector-elasticsearch" 2 | export ELASTICSEARCH_CONNECTOR_HOME="/opt/sds/stratio-connector-elasticsearch" 3 | export ELASTICSEARCH_CONNECTOR_LOGS="/var/logs/sds/stratio-connector-elasticsearch" 4 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/files_and_dirs/etc/init.d/connector_elasticsearch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: stratio-connector-elasticsearch 5 | # Required-Start: $remote_fs 6 | # Required-Stop: $remote_fs 7 | # Should-Stop: $all 8 | # Default-Start: 2 3 4 5 9 | # Default-Stop: 0 1 6 10 | # Short-Description: Crossdata connector 11 | # Description: Description for stratio-connector-elasticsearch 12 | ### END INIT INFO 13 | # Developed by pmadrid@stratio.com 14 | # Broken by alvaro@stratio.com 15 | # Version: 0.1 2014 16 | # When I learn scripting a bit better, I'll try to improve this one... 17 | 18 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 19 | INIT_HOME=`cd "${DIR}/.." >/dev/null; pwd` 20 | 21 | NAME="stratio-connector-elasticsearch" 22 | DESC="Description for stratio-connector-elasticsearch" 23 | BASEDIR=/opt/sds/connectors/elasticsearch 24 | CONFDIR=/etc/sds/connectors/elasticsearch 25 | LOGFILE=/var/log/sds/connectors/elasticsearch/connector_elasticsearch.log 26 | RUNFILE=$BASEDIR/bin/stratio-connector-elasticsearch 27 | pidDir=/var/run/sds/connectors 28 | serviceUser=stratio 29 | serviceGroup=stratio 30 | PIDFileName=connector_elasticsearch 31 | 32 | # If JAVA_HOME has not been set, try to determine it.ner 33 | JVM_SEARCH_DIRS="/usr/java/default /usr/java/latest /opt/java" 34 | 35 | if [ ! -d "$pidDir" ]; then 36 | mkdir -p "$pidDir" 37 | if [ $? -ne 0 ]; then exit 1; fi 38 | if [ -n "$serviceGroup" ]; then chown ${serviceUser}:${serviceGroup} "$pidDir"; fi 39 | if [ $? -ne 0 ]; then exit 1; fi 40 | fi 41 | pidFile="${pidDir}/${NAME}.pid" 42 | 43 | if [ ! -z "${PIDFileName}" ]; then 44 | pidFile="${pidDir}/${PIDFileName}.pid" 45 | fi 46 | 47 | # Returns 0 if the process with PID $1 is running. 48 | function checkProcessIsRunning { 49 | local pid="$1" 50 | if [ -z "$pid" -o "$pid" == " " ]; then return 1; fi 51 | ps -Af | grep ${pid} | grep java > /dev/null 2>&1 52 | if [ $? -ne 0 ]; then return 1; fi 53 | return 0; 54 | } 55 | 56 | # Returns 0 if the process with PID $1 is our Java service process. 57 | function checkProcessIsOurService { 58 | local pid="$1" 59 | ps -Af | grep ${pid} | grep java > /dev/null 2>&1 60 | if [ $? -ne 0 ]; then return 1; fi 61 | return 0; 62 | } 63 | 64 | # Returns 0 when the service is running and sets the variable $servicePid to the PID. 65 | function getServicePid { 66 | if [ ! -f $pidFile ]; then return 1; fi 67 | local servicePid="$(<$pidFile)" 68 | checkProcessIsRunning $servicePid || return 1 69 | checkProcessIsOurService $servicePid || return 1 70 | return 0; 71 | } 72 | 73 | function startServiceProcess { 74 | cd $BASEDIR || return 1 75 | rm -f $pidFile 76 | local cmd="$RUNFILE >>$LOGFILE 2>&1 & echo \$! >$pidFile" 77 | echo "Launching service process: ${NAME}" 78 | echo "" 79 | su $serviceUser -c "$cmd" || return 1 80 | sleep 0.1 81 | servicePid="$(<$pidFile)" 82 | echo "PID: ${pidFile} servicePid: ${servicePid}" 83 | if checkProcessIsRunning $servicePid; then :; else 84 | echo -e "\n${NAME} start failed, see logfile." 85 | rm -f $pidfile 86 | return 1 87 | fi 88 | return 0; 89 | } 90 | 91 | function stopServiceProcess { 92 | servicePid="$(<$pidFile)" 93 | kill $servicePid || return 1 94 | local killWaitTime=10 95 | for ((i=0; i<$killWaitTime*10; i++)); do 96 | checkProcessIsRunning $servicePid 97 | if [ $? -ne 0 ]; then 98 | rm -f $pidFile 99 | return 0 100 | fi 101 | sleep 0.1 102 | done 103 | echo -e "\n${NAME} did not terminate within 10 seconds, sending SIGKILL..." 104 | kill -s KILL $servicePid || return 1 105 | for ((i=0; i<$killWaitTime*10; i++)); do 106 | checkProcessIsRunning $servicePid 107 | if [ $? -ne 0 ]; then 108 | rm -f $pidFile 109 | return 0 110 | fi 111 | sleep 0.1 112 | done 113 | echo "Error: ${NAME} could not be stopped within 20 seconds!" 114 | return 1; 115 | } 116 | 117 | function startService { 118 | # Add any service start conditions here 119 | getServicePid 120 | if [ $? -eq 0 ]; then echo "${NAME} is already running"; return 0; fi 121 | echo "Starting ${NAME}" 122 | startServiceProcess 123 | if [ $? -ne 0 ]; then echo "Error starting ${NAME}" ; return 1; fi 124 | return 0; 125 | } 126 | 127 | function stopService { 128 | getServicePid 129 | if [ $? -ne 0 ]; then echo "${NAME} is not running"; return 0; fi 130 | echo "Stopping ${NAME} " 131 | stopServiceProcess 132 | if [ $? -ne 0 ]; then echo "Error stopping ${NAME}"; return 1; fi 133 | return 0; 134 | } 135 | 136 | function checkServiceStatus { 137 | echo "Checking for ${NAME}: " 138 | if [ ! -f "${CONFDIR}/connector-application.conf" ]; then 139 | echo "Error: Configuration file not found!" 140 | return 1 141 | fi 142 | if getServicePid; then 143 | local servicePid="$(<$pidFile)" 144 | echo "$DESC seems to be running (pid $servicePid)" 145 | return 0 146 | else 147 | echo "${NAME} seems to be stopped" 148 | return 1 149 | fi 150 | return 0; 151 | } 152 | 153 | case "$1" in 154 | start) 155 | startService 156 | retval=$? 157 | exit $retval 158 | ;; 159 | stop) 160 | stopService 161 | retval=$? 162 | exit $retval 163 | ;; 164 | restart) 165 | stopService && startService 166 | retval=$? 167 | exit $retval 168 | ;; 169 | status) 170 | checkServiceStatus 171 | retval=$? 172 | exit $retval 173 | ;; 174 | *) 175 | echo "Usage: $0 {start|stop|restart|status}" 176 | exit 1 177 | ;; 178 | esac 179 | 180 | exit 0 -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/scripts/post: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #RPM 4 | 5 | set -e 6 | 7 | GROUP='stratio' 8 | USER='stratio' 9 | DIR_INSTALL='/opt/sds/connectors/elasticsearch' 10 | DIR_CONF='/etc/sds/connectors/elasticsearch' 11 | DIR_LOG='/var/log/sds/connectors/elasticsearch' 12 | 13 | 14 | # Add stratio group if it doesn't already exists 15 | if ! getent group $GROUP >/dev/null 2>&1; then 16 | groupadd ${GROUP} 17 | fi 18 | 19 | # Add stratio user if it doesn't already exists 20 | if ! getent passwd $USER >/dev/null 2>&1; then 21 | [ -d /opt ] || mkdir /opt 22 | useradd -M -d /opt/sds -g ${GROUP} -s /bin/bash ${USER} 23 | else 24 | usermod -G $GROUP $USER 25 | fi 26 | 27 | if [ ! -d "$DIR_LOG" ]; then 28 | mkdir $DIR_LOG 29 | fi 30 | 31 | chown root:root /etc/init.d/connector_elasticsearch 32 | 33 | chown -R ${USER}:${GROUP} $DIR_INSTALL 34 | 35 | chown -R ${USER}:${GROUP} $DIR_CONF 36 | chown -R ${USER}:${GROUP} $DIR_LOG 37 | chmod -R 775 $DIR_INSTALL 38 | chmod 775 $DIR_LOG 39 | 40 | chmod 755 /etc/init.d/connector_elasticsearch 41 | chmod 755 /opt/sds/connectors/elasticsearch/bin/stratio-connector-elasticsearch 42 | chmod +x /etc/default/elasticsearch_connector 43 | 44 | sed -i 's!"$BASEDIR"/conf!/etc/sds/connectors/elasticsearch!g' /opt/sds/connectors/elasticsearch/bin/stratio-connector-elasticsearch 45 | 46 | export ELASTICSEARCH_CONNECTOR_LIB=/opt/sds/connectors/elasticsearch/ 47 | export ELASTICSEARCH_CONNECTOR_CONF="/etc/sds/connectors/elasticsearch" 48 | 49 | /sbin/chkconfig --add connector_elasticsearch 50 | 51 | exit 0 52 | 53 | 54 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/scripts/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | #DEB 6 | 7 | GROUP='stratio' 8 | USER='stratio' 9 | DIR_INSTALL='/opt/sds/connectors/elasticsearch' 10 | DIR_CONF='/etc/sds/connectors/elasticsearch' 11 | DIR_CONF='/etc/sds/connectors/elasticsearch' 12 | DIR_LOG='/var/log/sds/connectors/elasticsearch' 13 | 14 | 15 | chmod 755 /etc/init.d/connector_elasticsearch 16 | chmod 755 /opt/sds/connectors/elasticsearch/bin 17 | chmod +x /opt/sds/connectors/elasticsearch/bin/stratio-connector-elasticsearch 18 | chmod +x /etc/default/elasticsearch_connector 19 | export ELASTICSEARCH_CONNECTOR_LIB=/opt/sds/connectors/elasticsearch 20 | export ELASTICSEARCH_CONNECTOR_CONF="/etc/sds/connectors/elasticsearch" 21 | 22 | 23 | case "$1" in 24 | configure) 25 | 26 | # Add stratio group if it doesn't already exists 27 | if ! getent group $GROUP >/dev/null 2>&1; then 28 | groupadd ${GROUP} 29 | fi 30 | 31 | # Add stratio user if it doesn't already exists 32 | if ! getent passwd $USER >/dev/null 2>&1; then 33 | [ -d /opt ] || mkdir /opt 34 | useradd -M -d /opt/sds -g ${GROUP} -s /bin/bash ${USER} 35 | else 36 | usermod -G $GROUP $USER 37 | fi 38 | 39 | if [ ! -d "$DIR_LOG" ]; then 40 | mkdir $DIR_LOG 41 | fi 42 | 43 | chown root:root /etc/init.d/connector_elasticsearch 44 | 45 | chown -R ${USER}:${GROUP} $DIR_INSTALL 46 | chown -R ${USER}:${GROUP} $DIR_CONF 47 | chown -R ${USER}:${GROUP} $DIR_LOG 48 | chmod -R 775 $DIR_INSTALL 49 | chmod 775 $DIR_LOG 50 | 51 | sed -i 's!"$BASEDIR"/conf!/etc/sds/connectors/elasticsearch!g' /opt/sds/connectors/elasticsearch/bin/stratio-connector-elasticsearch 52 | 53 | update-rc.d connector_elasticsearch defaults 54 | ;; 55 | esac 56 | 57 | 58 | exit 0 59 | 60 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/scripts/pre: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #RPM 4 | 5 | set -e 6 | 7 | GROUP='stratio' 8 | USER='stratio' 9 | 10 | # Add stratio group if it doesn't already exists 11 | if ! getent group $GROUP >/dev/null 2>&1; then 12 | groupadd ${GROUP} 13 | fi 14 | 15 | # Add stratio user if it doesn't already exists 16 | if ! getent passwd $USER >/dev/null 2>&1; then 17 | [ -d /opt ] || mkdir /opt 18 | useradd -M -d /opt/sds -g ${GROUP} -s /bin/bash ${USER} 19 | else 20 | usermod -G $GROUP $USER 21 | fi 22 | 23 | exit 0 -------------------------------------------------------------------------------- /connector-elasticsearch/src/main/unix/scripts/preinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | #DEB 6 | 7 | GROUP='stratio' 8 | USER='stratio' 9 | 10 | case "$1" in 11 | configure) 12 | 13 | # Add stratio group if it doesn't already exists 14 | if ! getent group $GROUP >/dev/null 2>&1; then 15 | groupadd ${GROUP} 16 | fi 17 | 18 | # Add stratio user if it doesn't already exists 19 | if ! getent passwd $USER >/dev/null 2>&1; then 20 | [ -d /opt ] || mkdir /opt 21 | useradd -M -d /opt/sds -g ${GROUP} -s /bin/bash ${USER} 22 | else 23 | usermod -G $GROUP $USER 24 | fi 25 | 26 | esac 27 | 28 | 29 | exit 0 -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/ElasticsearchConnectorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core; 20 | 21 | import com.stratio.connector.elasticsearch.core.connection.ElasticSearchConnectionHandler; 22 | import com.stratio.connector.elasticsearch.core.connection.NodeConnection; 23 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 24 | import com.stratio.crossdata.common.data.ClusterName; 25 | import com.stratio.crossdata.common.security.ICredentials; 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | import org.mockito.internal.util.reflection.Whitebox; 31 | import org.powermock.core.classloader.annotations.PrepareForTest; 32 | import org.powermock.modules.junit4.PowerMockRunner; 33 | 34 | import java.util.HashMap; 35 | import java.util.Map; 36 | 37 | import static org.mockito.Mockito.*; 38 | 39 | /** 40 | * ElasticsearchConnector Tester. 41 | * 42 | * @author 43 | * @version 1.0 44 | */ 45 | @RunWith(PowerMockRunner.class) 46 | 47 | @PrepareForTest(value = { NodeConnection.class, ElasticsearchConnector.class }) 48 | public class ElasticsearchConnectorTest { 49 | 50 | private static final String CLUSTER_NAME = "CLUSTER_NAME"; 51 | private ElasticsearchConnector elasticsearchConnector = null; 52 | 53 | @Before 54 | public void before() throws Exception { 55 | 56 | elasticsearchConnector = new ElasticsearchConnector(); 57 | } 58 | 59 | @After 60 | public void after() throws Exception { 61 | } 62 | 63 | /** 64 | * Method: init(IConfiguration configuration) 65 | */ 66 | 67 | /** 68 | * Method: close() 69 | */ 70 | @Test 71 | public void testConnect() throws Exception { 72 | 73 | ICredentials iCredentials = mock(ICredentials.class); 74 | ClusterName clusterName = new ClusterName(CLUSTER_NAME); 75 | Map connectorOptions = new HashMap<>(); 76 | Map clusterOptions = new HashMap<>(); 77 | 78 | ConnectorClusterConfig config = new ConnectorClusterConfig(clusterName, connectorOptions, clusterOptions); 79 | 80 | ElasticSearchConnectionHandler connectionHandle = mock(ElasticSearchConnectionHandler.class); 81 | Whitebox.setInternalState(elasticsearchConnector, "connectionHandler", connectionHandle); 82 | 83 | elasticsearchConnector.connect(iCredentials, config); 84 | 85 | verify(connectionHandle, times(1)).createConnection(iCredentials, config); 86 | 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/configuration/ElasticsearchClientConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.configuration; 20 | 21 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 22 | import com.stratio.crossdata.common.data.ClusterName; 23 | import org.elasticsearch.common.settings.Settings; 24 | import org.elasticsearch.common.transport.TransportAddress; 25 | import org.junit.After; 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | import java.util.Collections; 30 | import java.util.HashMap; 31 | import java.util.Map; 32 | 33 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.*; 34 | import static junit.framework.TestCase.assertEquals; 35 | import static junit.framework.TestCase.assertNotNull; 36 | 37 | /** 38 | * ElasticsearchClientConfiguration Tester. 39 | * 40 | * @author 41 | * @version 1.0 42 | */ 43 | public class ElasticsearchClientConfigurationTest { 44 | 45 | private static final ClusterName THE_CLUSTER_NAME = new ClusterName("cluster_name"); 46 | 47 | @Before 48 | public void before() throws Exception { 49 | } 50 | 51 | @After 52 | public void after() throws Exception { 53 | } 54 | 55 | /** 56 | * Method: getSettings(ConnectorClusterConfig configuration) 57 | */ 58 | @Test 59 | public void testGetSettings() throws Exception { 60 | 61 | 62 | Map connectorOptions = new HashMap<>(); 63 | connectorOptions.put(NODE_DATA.getManifestOption(), "true"); 64 | connectorOptions.put(NODE_MASTER.getManifestOption(), "true"); 65 | 66 | Map clusterOptions = new HashMap<>(); 67 | clusterOptions.put(HOST.getManifestOption(), "localhost"); 68 | clusterOptions.put(PORT.getManifestOption(), "9301"); 69 | 70 | 71 | ConnectorClusterConfig configuration = new ConnectorClusterConfig(THE_CLUSTER_NAME, connectorOptions,clusterOptions); 72 | 73 | Settings result = ElasticsearchClientConfiguration.getSettings(configuration); 74 | 75 | assertNotNull("Result is not null", result); 76 | assertEquals("The node must be true", "true", result.get(NODE_DATA.getElasticSearchOption())); 77 | assertEquals("The node master must be true", "true", result.get(NODE_MASTER.getElasticSearchOption())); 78 | 79 | assertEquals("The transport sniff must be "+TRANSPORT_SNIFF.getDefaultValue()[0], TRANSPORT_SNIFF 80 | .getDefaultValue()[0], 81 | result.get(TRANSPORT_SNIFF.getElasticSearchOption())); 82 | 83 | assertEquals("The cluster name sniff must be Cluster Name", CLUSTER_NAME.getDefaultValue()[0], 84 | result.get(CLUSTER_NAME.getElasticSearchOption())); 85 | 86 | assertEquals("The cluster name sniff must be "+COERCE.getDefaultValue()[0], COERCE.getDefaultValue()[0], 87 | result.get(COERCE.getElasticSearchOption())); 88 | 89 | assertEquals("The cluster name sniff must be "+DYNAMIC.getDefaultValue()[0], DYNAMIC.getDefaultValue()[0], 90 | result.get(DYNAMIC.getElasticSearchOption())); 91 | 92 | } 93 | 94 | /** 95 | * Method: getTransportAddress(ConnectorClusterConfig config) 96 | */ 97 | @Test 98 | public void testGetTransporAddress() throws Exception { 99 | Map clusterOptions = new HashMap<>(); 100 | clusterOptions.put(HOST.getManifestOption(), "10.200.0.58,10.200.0.59,10.200.0.60"); 101 | clusterOptions.put(PORT.getManifestOption(), "2800,2802,2809"); 102 | ConnectorClusterConfig configuration = new ConnectorClusterConfig(THE_CLUSTER_NAME, 103 | Collections.EMPTY_MAP, clusterOptions); 104 | 105 | TransportAddress[] result = ElasticsearchClientConfiguration.getTransportAddress(configuration); 106 | assertNotNull("The result is not null", result); 107 | assertEquals("The result number is correct", 3, result.length); 108 | assertEquals("The first address is correct", "inet[/10.200.0.58:2800]", result[0].toString()); 109 | assertEquals("The second address is correct", "inet[/10.200.0.59:2802]", result[1].toString()); 110 | assertEquals("The third address is correct", "inet[/10.200.0.60:2809]", result[2].toString()); 111 | 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/connection/NodeConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.connection; 20 | 21 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 22 | import com.stratio.crossdata.common.data.ClusterName; 23 | import com.stratio.crossdata.common.security.ICredentials; 24 | import org.elasticsearch.client.Client; 25 | import org.elasticsearch.common.settings.Settings; 26 | import org.elasticsearch.node.Node; 27 | import org.elasticsearch.node.NodeBuilder; 28 | import org.junit.After; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.mockito.Mock; 33 | import org.mockito.internal.util.reflection.Whitebox; 34 | import org.powermock.core.classloader.annotations.PrepareForTest; 35 | import org.powermock.modules.junit4.PowerMockRunner; 36 | 37 | import java.util.Collections; 38 | import java.util.Map; 39 | 40 | import static junit.framework.TestCase.assertNotNull; 41 | import static junit.framework.TestCase.assertNull; 42 | import static org.mockito.Matchers.any; 43 | import static org.mockito.Mockito.*; 44 | import static org.powermock.api.mockito.PowerMockito.mockStatic; 45 | import static org.powermock.api.mockito.PowerMockito.when; 46 | 47 | /** 48 | * NodeConnection Tester. 49 | * 50 | * @author 51 | * @version 1.0 52 | */ 53 | @RunWith(PowerMockRunner.class) 54 | @PrepareForTest(NodeBuilder.class) 55 | public class NodeConnectionTest { 56 | 57 | @Mock Client client; 58 | NodeConnection nodeConnection; 59 | @Mock Node node; 60 | 61 | @Before 62 | public void before() throws Exception { 63 | ICredentials credentials = mock(ICredentials.class); 64 | 65 | Map options = Collections.EMPTY_MAP; 66 | 67 | ConnectorClusterConfig configuration = new ConnectorClusterConfig(new ClusterName("CLUSTER_NAME"), options, 68 | options); 69 | mockStatic(NodeBuilder.class); 70 | NodeBuilder nodeBuilder = mock(NodeBuilder.class); 71 | when(nodeBuilder.settings(any(Settings.class))).thenReturn(nodeBuilder); 72 | when(nodeBuilder.node()).thenReturn(node); 73 | when(node.client()).thenReturn(client); 74 | when(NodeBuilder.nodeBuilder()).thenReturn(nodeBuilder); 75 | 76 | nodeConnection = new NodeConnection(credentials, configuration); 77 | 78 | assertNotNull("The connection is not null", Whitebox.getInternalState(nodeConnection, "elasticClient")); 79 | 80 | } 81 | 82 | @After 83 | public void after() throws Exception { 84 | } 85 | 86 | /** 87 | * Method: close() 88 | */ 89 | @Test 90 | public void testClose() throws Exception { 91 | 92 | Whitebox.setInternalState(nodeConnection, "elasticClient", client); 93 | Whitebox.setInternalState(nodeConnection, "node", node); 94 | 95 | nodeConnection.close(); 96 | 97 | verify(node, times(1)).close(); 98 | assertNull("The connection is null", Whitebox.getInternalState(nodeConnection, "elasticClient")); 99 | assertNull("The node is null", Whitebox.getInternalState(nodeConnection, "node")); 100 | 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/connection/TransportConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.connection; 20 | 21 | import com.stratio.crossdata.common.connector.ConnectorClusterConfig; 22 | import com.stratio.crossdata.common.data.ClusterName; 23 | import com.stratio.crossdata.common.security.ICredentials; 24 | import org.elasticsearch.client.Client; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.mockito.Mock; 29 | import org.mockito.internal.util.reflection.Whitebox; 30 | import org.powermock.modules.junit4.PowerMockRunner; 31 | 32 | import java.util.Collections; 33 | import java.util.HashMap; 34 | import java.util.Map; 35 | 36 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.HOST; 37 | import static com.stratio.connector.elasticsearch.core.configuration.ConfigurationOptions.PORT; 38 | import static junit.framework.TestCase.assertNotNull; 39 | import static org.mockito.Mockito.*; 40 | 41 | /** 42 | * TransportConnection Tester. 43 | * 44 | * @author 45 | * @version 1.0 46 | */ 47 | @RunWith(PowerMockRunner.class) 48 | public class TransportConnectionTest { 49 | 50 | @Mock Client client; 51 | TransportConnection transportConnection; 52 | 53 | @Before 54 | public void before() throws Exception { 55 | ICredentials credentials = mock(ICredentials.class); 56 | 57 | Map clusterOptiosn = new HashMap<>(); 58 | clusterOptiosn.put(HOST.getManifestOption(), "10.200.0.58,10.200.0.59,10.200.0.60"); 59 | clusterOptiosn.put(PORT.getManifestOption(), "2800,2802,2809"); 60 | ConnectorClusterConfig configuration = new ConnectorClusterConfig(new ClusterName("CLUSTER_NAME"), 61 | Collections.EMPTY_MAP, clusterOptiosn); 62 | transportConnection = new TransportConnection(credentials, configuration); 63 | 64 | assertNotNull("The connection is not null", Whitebox.getInternalState(transportConnection, "elasticClient")); 65 | 66 | } 67 | 68 | /** 69 | * Method: close() 70 | */ 71 | @Test 72 | public void testClose() throws Exception { 73 | 74 | Whitebox.setInternalState(transportConnection, "elasticClient", client); 75 | transportConnection.close(); 76 | 77 | verify(client, times(1)).close(); 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/ElasticsearchQueryEngineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine; 20 | 21 | import com.stratio.connector.commons.connection.Connection; 22 | import com.stratio.connector.commons.connection.ConnectionHandler; 23 | import com.stratio.connector.commons.engine.query.ProjectParsed; 24 | import com.stratio.connector.elasticsearch.core.engine.query.ConnectorQueryBuilder; 25 | import com.stratio.connector.elasticsearch.core.engine.query.ConnectorQueryExecutor; 26 | import com.stratio.connector.elasticsearch.core.engine.query.ConnectorQueryParser; 27 | import com.stratio.connector.elasticsearch.core.engine.query.ESProjectParsedValidator; 28 | import com.stratio.crossdata.common.connector.IResultHandler; 29 | import com.stratio.crossdata.common.data.ResultSet; 30 | import com.stratio.crossdata.common.exceptions.ConnectorException; 31 | import com.stratio.crossdata.common.exceptions.ExecutionException; 32 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 33 | import com.stratio.crossdata.common.logicalplan.LogicalWorkflow; 34 | import com.stratio.crossdata.common.logicalplan.Project; 35 | import com.stratio.crossdata.common.result.QueryResult; 36 | import org.elasticsearch.action.search.SearchRequestBuilder; 37 | import org.elasticsearch.client.Client; 38 | import org.junit.After; 39 | import org.junit.Before; 40 | import org.junit.Test; 41 | import org.junit.runner.RunWith; 42 | import org.mockito.Mock; 43 | import org.powermock.core.classloader.annotations.PrepareForTest; 44 | import org.powermock.modules.junit4.PowerMockRunner; 45 | 46 | import static junit.framework.TestCase.assertEquals; 47 | import static org.mockito.Mockito.when; 48 | import static org.powermock.api.mockito.PowerMockito.mock; 49 | import static org.powermock.api.mockito.PowerMockito.whenNew; 50 | 51 | /** 52 | * ElasticsearchQueryEngine Tester. 53 | * 54 | * @author 55 | * @version 1.0 56 | */ 57 | @RunWith(PowerMockRunner.class) 58 | @PrepareForTest({ ElasticsearchQueryEngine.class, ConnectorQueryParser.class, ConnectorQueryBuilder.class, 59 | ConnectorQueryExecutor.class }) 60 | public class ElasticsearchQueryEngineTest { 61 | 62 | @Mock ConnectionHandler connectionHandle; 63 | @Mock private ConnectorQueryParser queryParser; 64 | @Mock private ConnectorQueryBuilder queryBuilder; 65 | @Mock private ConnectorQueryExecutor queryExecutor; 66 | private ElasticsearchQueryEngine elasticsearchQueryEngine; 67 | 68 | @Before 69 | public void before() throws Exception { 70 | 71 | whenNew(ConnectorQueryParser.class).withNoArguments().thenReturn(queryParser); 72 | whenNew(ConnectorQueryBuilder.class).withNoArguments().thenReturn(queryBuilder); 73 | whenNew(ConnectorQueryExecutor.class).withNoArguments().thenReturn(queryExecutor); 74 | 75 | elasticsearchQueryEngine = new ElasticsearchQueryEngine(connectionHandle); 76 | 77 | } 78 | 79 | @After 80 | public void after() throws Exception { 81 | } 82 | 83 | /** 84 | * Method: execute(Project logicalWorkflow, Connection connection) 85 | */ 86 | @Test 87 | public void testExecute() throws Exception { 88 | 89 | Project project = mock(Project.class); 90 | Connection connection = mock(Connection.class); 91 | Client eSConnection = mock(Client.class); 92 | when(connection.getNativeConnection()).thenReturn(eSConnection); 93 | 94 | ProjectParsed projectParsed = mock(ProjectParsed.class); 95 | ESProjectParsedValidator projectValidator = mock(ESProjectParsedValidator.class); 96 | whenNew(ESProjectParsedValidator.class).withNoArguments().thenReturn(projectValidator); 97 | whenNew(ProjectParsed.class).withArguments(project, projectValidator).thenReturn(projectParsed); 98 | 99 | 100 | 101 | SearchRequestBuilder searchRequestBuilder = mock(SearchRequestBuilder.class); 102 | when(queryBuilder.buildQuery(eSConnection, projectParsed)).thenReturn(searchRequestBuilder); 103 | 104 | ResultSet resultSet = mock(ResultSet.class); 105 | 106 | QueryResult queryResult = QueryResult.createQueryResult(resultSet, 0, true); 107 | when(queryExecutor.executeQuery(eSConnection, searchRequestBuilder, projectParsed)).thenReturn(queryResult); 108 | 109 | QueryResult returnQueryResult = elasticsearchQueryEngine.execute(project, connection); 110 | assertEquals("The query result is correct", queryResult, returnQueryResult); 111 | 112 | } 113 | 114 | /** 115 | * Method: asyncExecute(String queryId, LogicalWorkflow workflow, IResultHandler resultHandler) 116 | */ 117 | @Test(expected = ExecutionException.class) 118 | public void testAsyncExecute() throws ConnectorException { 119 | elasticsearchQueryEngine.asyncExecute("", mock(LogicalWorkflow.class), mock(IResultHandler.class)); 120 | } 121 | 122 | /** 123 | * Method: stop(String queryId) 124 | */ 125 | @Test(expected = UnsupportedException.class) 126 | public void testStop() throws UnsupportedException, ExecutionException { 127 | elasticsearchQueryEngine.stop(""); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/ElasticsearchStorageEngineExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine; 20 | 21 | import com.stratio.connector.commons.connection.Connection; 22 | import com.stratio.connector.elasticsearch.core.connection.ElasticSearchConnectionHandler; 23 | import com.stratio.connector.elasticsearch.core.engine.utils.IndexRequestBuilderCreator; 24 | import com.stratio.crossdata.common.data.*; 25 | import com.stratio.crossdata.common.exceptions.ExecutionException; 26 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 27 | import com.stratio.crossdata.common.metadata.ColumnMetadata; 28 | import com.stratio.crossdata.common.metadata.IndexMetadata; 29 | import com.stratio.crossdata.common.metadata.TableMetadata; 30 | import com.stratio.crossdata.common.statements.structures.Selector; 31 | import org.elasticsearch.client.Client; 32 | import org.junit.Before; 33 | import org.junit.Rule; 34 | import org.junit.Test; 35 | import org.junit.rules.ExpectedException; 36 | import org.mockito.internal.util.reflection.Whitebox; 37 | 38 | import java.util.LinkedHashMap; 39 | import java.util.LinkedList; 40 | import java.util.Map; 41 | 42 | import static org.mockito.Mockito.when; 43 | import static org.powermock.api.mockito.PowerMockito.mock; 44 | 45 | /** 46 | * ElasticsearchStorageEngine Tester. 47 | * 48 | * @author 49 | * @version 1.0 50 | */ 51 | 52 | public class ElasticsearchStorageEngineExceptionTest { 53 | 54 | private static final String CLUSTER_NAME = "CLUSTER NAME".toLowerCase(); 55 | private static final String INDEX_NAME = "INDEX_NAME".toLowerCase(); 56 | private static final String TYPE_NAME = "TYPE_NAME".toLowerCase(); 57 | private TableName tableName = new TableName(INDEX_NAME, TYPE_NAME); 58 | private static final String ROW_NAME = "row_name"; 59 | private static final Integer INTEGER_CELL_VALUE = new Integer(5); 60 | 61 | @Rule 62 | public ExpectedException exception = ExpectedException.none(); 63 | 64 | private IndexRequestBuilderCreator indexRequestBuilderCreator; 65 | private ElasticSearchConnectionHandler connectionHandler; 66 | private Connection connection; 67 | private Client client; 68 | 69 | private ElasticsearchStorageEngine elasticsearchStorageEngine; 70 | private LinkedHashMap columns = null; 71 | private Map options = null; 72 | private Map indexes = null; 73 | private ClusterName clusterRef = null; 74 | LinkedList partitionKey = new LinkedList(); 75 | LinkedList clusterKey = new LinkedList(); 76 | 77 | @Before 78 | public void before() { 79 | 80 | indexRequestBuilderCreator = mock(IndexRequestBuilderCreator.class); 81 | connectionHandler = mock(ElasticSearchConnectionHandler.class); 82 | connection = mock(Connection.class); 83 | client = mock(Client.class); 84 | 85 | elasticsearchStorageEngine = new ElasticsearchStorageEngine(connectionHandler); 86 | 87 | Whitebox.setInternalState(elasticsearchStorageEngine, "indexRequestBuilderCreator", indexRequestBuilderCreator); 88 | 89 | } 90 | 91 | @Test 92 | public void testInsertExecutionException() 93 | throws ExecutionException, UnsupportedException { 94 | 95 | exception.expect(ExecutionException.class); 96 | exception.expectMessage("Msg"); 97 | 98 | when(connectionHandler.getConnection(CLUSTER_NAME)).thenThrow(new ExecutionException("Msg")); 99 | 100 | TableMetadata targetTable = new TableMetadata(tableName, options, columns, indexes, clusterRef, partitionKey, 101 | clusterKey); 102 | ClusterName clusterName = new ClusterName(CLUSTER_NAME); 103 | 104 | boolean isNotExists = false; 105 | elasticsearchStorageEngine.insert(clusterName, targetTable, createRow(ROW_NAME, INTEGER_CELL_VALUE),isNotExists); 106 | 107 | } 108 | 109 | private Row createRow(String rowKey, Object cellValue) { 110 | Cell cell = new Cell(cellValue); 111 | Row row = new Row(rowKey, cell); 112 | return row; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/metadata/AlterTableFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.metadata; 20 | 21 | import com.stratio.crossdata.common.data.AlterOperation; 22 | import com.stratio.crossdata.common.data.AlterOptions; 23 | import com.stratio.crossdata.common.exceptions.ExecutionException; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | import java.util.Collections; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | 31 | /** 32 | * AlterTableFactory Tester. 33 | * 34 | * @author 35 | * @version 1.0 36 | 37 | */ 38 | public class AlterTableFactoryTest { 39 | 40 | @Before 41 | public void before() throws Exception { 42 | 43 | } 44 | 45 | /** 46 | * Method: createHandler(AlterOptions alterOptions) 47 | */ 48 | @Test 49 | public void testCreateAddColumnHandeler() throws Exception { 50 | AlterOptions alterOptions = new AlterOptions(AlterOperation.ADD_COLUMN, Collections.EMPTY_MAP, null); 51 | assertEquals("The instance is correct", AddColumnHandler.class.getCanonicalName(), AlterTableFactory 52 | .createHandler(alterOptions).getClass().getCanonicalName()); 53 | } 54 | 55 | @Test(expected = ExecutionException.class) 56 | public void testAlterColumnHandler() throws Exception { 57 | AlterOptions alterOptions = new AlterOptions(AlterOperation.ALTER_COLUMN, Collections.EMPTY_MAP, null); 58 | assertEquals("The instance is correct", AddColumnHandler.class.getCanonicalName(), AlterTableFactory 59 | .createHandler(alterOptions).getClass().getCanonicalName()); 60 | } 61 | 62 | @Test(expected = ExecutionException.class) 63 | public void testAlterOptionsHandeler() throws Exception { 64 | AlterOptions alterOptions = new AlterOptions(AlterOperation.ALTER_OPTIONS, Collections.EMPTY_MAP, null); 65 | assertEquals("The instance is correct", AddColumnHandler.class.getCanonicalName(), AlterTableFactory 66 | .createHandler(alterOptions).getClass().getCanonicalName()); 67 | } 68 | 69 | @Test(expected = ExecutionException.class) 70 | public void testDropColumnHandeler() throws Exception { 71 | AlterOptions alterOptions = new AlterOptions(AlterOperation.DROP_COLUMN, Collections.EMPTY_MAP, null); 72 | assertEquals("The instance is correct", AddColumnHandler.class.getCanonicalName(), AlterTableFactory 73 | .createHandler(alterOptions).getClass().getCanonicalName()); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/ConnectorQueryParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query; 20 | 21 | import com.stratio.crossdata.common.data.ClusterName; 22 | import com.stratio.crossdata.common.data.ColumnName; 23 | import com.stratio.crossdata.common.data.TableName; 24 | import com.stratio.crossdata.common.logicalplan.Filter; 25 | import com.stratio.crossdata.common.logicalplan.LogicalStep; 26 | import com.stratio.crossdata.common.logicalplan.Project; 27 | import com.stratio.crossdata.common.logicalplan.Select; 28 | import com.stratio.crossdata.common.metadata.ColumnType; 29 | import com.stratio.crossdata.common.metadata.DataType; 30 | import com.stratio.crossdata.common.metadata.Operations; 31 | import com.stratio.crossdata.common.statements.structures.*; 32 | import org.junit.After; 33 | import org.junit.Before; 34 | import org.junit.Test; 35 | 36 | import java.util.*; 37 | 38 | import static org.junit.Assert.assertEquals; 39 | import static org.junit.Assert.assertNotNull; 40 | 41 | /** 42 | * LogicalPlanExecutor Tester. 43 | * 44 | * @author 45 | * @version 1.0 46 | */ 47 | public class ConnectorQueryParserTest { 48 | 49 | private static final String INDEX_NAME = "INDEX_NAME".toLowerCase(); 50 | private static final String TYPE_NAME = "TYPE_NAME".toLowerCase(); 51 | private static final String COLUMN_NAME = "COLUMN_NAME".toLowerCase(); 52 | private static final String STRING_COLUMN_VALUE = "STRING_COLUMN_VALUE".toLowerCase(); 53 | private static final String CLUSTER_NAME = "CLUSTER_NAME".toLowerCase(); 54 | ConnectorQueryParser queryParser; 55 | 56 | @Before 57 | public void before() throws Exception { 58 | 59 | queryParser = new ConnectorQueryParser(); 60 | } 61 | 62 | @After 63 | public void after() throws Exception { 64 | } 65 | 66 | /** 67 | * Method: transformLogicalWorkFlow(LogicalWorkflow logicalPlan) 68 | */ 69 | 70 | @Test 71 | public void testTransformSimpleWorkFlow() throws Exception { 72 | 73 | Project logicalWorkflow = createLogicalWorkFlow(); 74 | 75 | ConnectorQueryData queryData = queryParser.transformLogicalWorkFlow(logicalWorkflow); 76 | 77 | Collection filters = queryData.getFilter(); 78 | 79 | assertNotNull("The filter is not null", filters); 80 | assertEquals("The filter size is correct", 1, filters.size()); 81 | Filter filter = (Filter) filters.toArray()[0]; 82 | 83 | assertEquals("The filter operation is correct", Operations.FILTER_FUNCTION_EQ, filter.getOperations().iterator().next()); 84 | assertEquals("The left term is type correct,", ColumnSelector.class.getCanonicalName(), 85 | filter.getRelation().getLeftTerm().getClass().getCanonicalName()); 86 | assertEquals("The filter table is correct", TYPE_NAME, 87 | ((ColumnSelector) filter.getRelation().getLeftTerm()).getName().getTableName().getName()); 88 | assertEquals("The operator is correct", Operator.EQ, filter.getRelation().getOperator()); 89 | assertEquals("The right term is correct", STRING_COLUMN_VALUE, 90 | ((StringSelector) filter.getRelation().getRightTerm()).getValue()); 91 | 92 | Project projection = queryData.getProjection(); 93 | assertNotNull("The projection is not null", projection); 94 | assertEquals("The type in the projection is correct", TYPE_NAME, projection.getTableName().getName()); 95 | assertEquals("The index in the projection is correct", INDEX_NAME, 96 | projection.getTableName().getCatalogName().getName()); 97 | 98 | } 99 | 100 | private Project createLogicalWorkFlow() { 101 | 102 | Set operations = new HashSet<>(); 103 | operations.add(Operations.FILTER_FUNCTION_EQ); 104 | 105 | List initalSteps = new ArrayList<>(); 106 | 107 | ColumnName columnName = new ColumnName(INDEX_NAME, TYPE_NAME, COLUMN_NAME); 108 | Relation filterRelation = new Relation(new ColumnSelector(columnName), 109 | Operator.EQ, new StringSelector(STRING_COLUMN_VALUE)); 110 | Filter filter = new Filter(operations, filterRelation); 111 | 112 | Project project = new Project(operations, new TableName(INDEX_NAME, TYPE_NAME), new ClusterName(CLUSTER_NAME)); 113 | project.setNextStep(filter); 114 | initalSteps.add(project); 115 | 116 | Map column = new HashMap<>(); 117 | Selector selector = new ColumnSelector(new ColumnName(INDEX_NAME, TYPE_NAME, COLUMN_NAME)); 118 | column.put(selector, "alias" + COLUMN_NAME); 119 | 120 | Map type = new HashMap<>(); 121 | type.put("alias" + COLUMN_NAME, new ColumnType(DataType.TEXT)); 122 | Map typeColumName = new HashMap<>(); 123 | typeColumName.put(selector, new ColumnType(DataType.TEXT)); 124 | 125 | Set operations2 = new HashSet<>(); 126 | operations2.add(Operations.SELECT_OPERATOR); 127 | Select select = new Select(operations2, column, type, typeColumName); 128 | 129 | filter.setNextStep(select); 130 | 131 | return project; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/ESProjectParsedValidatorTest.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.query; 2 | 3 | import com.stratio.connector.commons.engine.query.ProjectParsed; 4 | import com.stratio.crossdata.common.data.ClusterName; 5 | import com.stratio.crossdata.common.data.TableName; 6 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 7 | import com.stratio.crossdata.common.logicalplan.Window; 8 | import org.junit.Test; 9 | 10 | import static org.mockito.Mockito.mock; 11 | import static org.mockito.Mockito.when; 12 | 13 | /** 14 | * ESProjectParsedValidator Tester. 15 | * 16 | * @author 17 | * @version 1.0 18 | */ 19 | public class ESProjectParsedValidatorTest { 20 | 21 | private static final ClusterName CLUSTER_NAME = new ClusterName("clusterName"); 22 | private static final TableName TABLE_NAME = new TableName("catalog_name", "table_name"); 23 | 24 | /** 25 | * 26 | * Method: validate(ProjectParsed projectParsed) 27 | * 28 | */ 29 | @Test(expected = UnsupportedException.class) 30 | public void testValidate() throws Exception { 31 | 32 | ESProjectParsedValidator esProjectParsedValidator = new ESProjectParsedValidator(); 33 | 34 | ProjectParsed projectParsed = mock(ProjectParsed.class); 35 | Window window = mock(Window.class); 36 | when(projectParsed.getWindow()).thenReturn(window); 37 | 38 | esProjectParsedValidator.validate(projectParsed); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/ESFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 22 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 23 | import com.stratio.crossdata.common.statements.structures.Selector; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | import org.mockito.Mockito; 27 | 28 | import java.util.Collections; 29 | 30 | 31 | public class ESFunctionTest { 32 | 33 | @Test(expected = UnsupportedException.class) 34 | public void testFailBuildFunction() throws UnsupportedException { 35 | buildFunction("not supported", null); 36 | } 37 | 38 | private void buildFunction(String functionName, Class expectedClass) throws UnsupportedException { 39 | 40 | FunctionRelation function = Mockito.mock(FunctionRelation.class); 41 | Mockito.when(function.getFunctionName()).thenReturn(functionName); 42 | Mockito.when(function.getFunctionSelectors()).thenReturn(Collections.emptyList()); 43 | 44 | //Experimentation 45 | ESFunction result = ESFunction.build(function); 46 | 47 | //Expectations 48 | Assert.assertEquals(result.getClass(), expectedClass); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/FuzzyMultiMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.data.ColumnName; 22 | import com.stratio.crossdata.common.data.TableName; 23 | import com.stratio.crossdata.common.exceptions.ExecutionException; 24 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 25 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 26 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 27 | import com.stratio.crossdata.common.statements.structures.Selector; 28 | import com.stratio.crossdata.common.statements.structures.StringSelector; 29 | import org.elasticsearch.index.query.QueryBuilder; 30 | import org.junit.Assert; 31 | import org.junit.Test; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | public class FuzzyMultiMatchTest { 37 | 38 | 39 | @Test 40 | public void testMatch() throws UnsupportedException, ExecutionException { 41 | 42 | List parameters = new ArrayList<>(); 43 | TableName tableName = new TableName("catalog", "table"); 44 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 45 | parameters.add(new ColumnSelector(new ColumnName(tableName, "col2Name"))); 46 | parameters.add(new StringSelector("*_colName")); 47 | parameters.add(new StringSelector("value")); 48 | parameters.add(new StringSelector("0.6")); 49 | 50 | FunctionRelation function = new FunctionRelation(ESFunction.MULTI_MATCH_FUZZY, parameters,tableName); 51 | ESFunction match = ESFunction.build(function); 52 | 53 | //Experimentation 54 | QueryBuilder builder = match.buildQuery(); 55 | 56 | //Expectations 57 | String expected = "{\"multi_match\":{\"query\":\"value\",\"fields\":[\"colName\",\"col2Name\",\"*_colName\"],\"fuzziness\":\"0.6\"}}"; 58 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/FuzzyTest.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 2 | 3 | import com.stratio.crossdata.common.data.ColumnName; 4 | import com.stratio.crossdata.common.data.TableName; 5 | import com.stratio.crossdata.common.exceptions.ExecutionException; 6 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 7 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 8 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 9 | import com.stratio.crossdata.common.statements.structures.Selector; 10 | import com.stratio.crossdata.common.statements.structures.StringSelector; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.junit.Assert; 13 | import org.junit.Test; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by lcisneros on 17/06/15. 20 | */ 21 | public class FuzzyTest { 22 | @Test 23 | public void testMatch() throws UnsupportedException, ExecutionException { 24 | 25 | List parameters = new ArrayList<>(); 26 | TableName tableName = new TableName("catalog", "table"); 27 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 28 | parameters.add(new StringSelector("fieldValue")); 29 | parameters.add(new StringSelector("1")); 30 | 31 | FunctionRelation function = new FunctionRelation(ESFunction.FUZZY, parameters,tableName); 32 | ESFunction match = ESFunction.build(function); 33 | 34 | //Experimentation 35 | QueryBuilder builder = match.buildQuery(); 36 | 37 | //Expectations 38 | String expected = "{\"fuzzy\":{\"colName\":{\"value\":\"fieldValue\",\"fuzziness\":\"1\"}}}"; 39 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MatchPhraseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.data.ColumnName; 22 | import com.stratio.crossdata.common.data.TableName; 23 | import com.stratio.crossdata.common.exceptions.ExecutionException; 24 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 25 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 26 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 27 | import com.stratio.crossdata.common.statements.structures.Selector; 28 | import com.stratio.crossdata.common.statements.structures.StringSelector; 29 | import org.elasticsearch.index.query.QueryBuilder; 30 | import org.junit.Assert; 31 | import org.junit.Test; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | /** 37 | * Created by lcisneros on 16/06/15. 38 | */ 39 | public class MatchPhraseTest { 40 | 41 | @Test 42 | public void testMatch() throws UnsupportedException, ExecutionException { 43 | 44 | List parameters = new ArrayList<>(); 45 | TableName tableName = new TableName("catalog", "table"); 46 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 47 | parameters.add(new StringSelector("phrase")); 48 | 49 | FunctionRelation function = new FunctionRelation(ESFunction.MATCH_PHRASE, parameters,tableName); 50 | ESFunction match = ESFunction.build(function); 51 | 52 | //Experimentation 53 | QueryBuilder builder = match.buildQuery(); 54 | 55 | //Expectations 56 | String expected = "{\"match\":{\"colName\":{\"query\":\"phrase\",\"type\":\"phrase\"}}}"; 57 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MatchPrefixTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | 22 | import com.stratio.crossdata.common.data.ColumnName; 23 | import com.stratio.crossdata.common.data.TableName; 24 | import com.stratio.crossdata.common.exceptions.ExecutionException; 25 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 26 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 27 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 28 | import com.stratio.crossdata.common.statements.structures.Selector; 29 | import com.stratio.crossdata.common.statements.structures.StringSelector; 30 | import org.elasticsearch.index.query.QueryBuilder; 31 | import org.junit.Assert; 32 | import org.junit.Test; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | public class MatchPrefixTest { 38 | 39 | @Test 40 | public void testMatch() throws UnsupportedException, ExecutionException { 41 | 42 | List parameters = new ArrayList<>(); 43 | TableName tableName = new TableName("catalog", "table"); 44 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 45 | parameters.add(new StringSelector("value")); 46 | 47 | FunctionRelation function = new FunctionRelation(ESFunction.MATCH_PREFIX, parameters,tableName); 48 | ESFunction match = ESFunction.build(function); 49 | 50 | //Experimentation 51 | QueryBuilder builder = match.buildQuery(); 52 | 53 | //Expectations 54 | String expected = "{\"prefix\":{\"colName\":\"value\"}}"; 55 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | 22 | import com.stratio.crossdata.common.data.ColumnName; 23 | import com.stratio.crossdata.common.data.TableName; 24 | import com.stratio.crossdata.common.exceptions.ExecutionException; 25 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 26 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 27 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 28 | import com.stratio.crossdata.common.statements.structures.Selector; 29 | import com.stratio.crossdata.common.statements.structures.StringSelector; 30 | import org.elasticsearch.index.query.QueryBuilder; 31 | import org.junit.Assert; 32 | import org.junit.Test; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | public class MatchTest { 38 | 39 | @Test 40 | public void testMatch() throws UnsupportedException, ExecutionException { 41 | 42 | List parameters = new ArrayList<>(); 43 | TableName tableName = new TableName("catalog", "table"); 44 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 45 | parameters.add(new StringSelector("value")); 46 | parameters.add(new StringSelector("100%")); 47 | 48 | FunctionRelation function = new FunctionRelation(ESFunction.CONTAINS, parameters,tableName); 49 | ESFunction match = ESFunction.build(function); 50 | 51 | //Experimentation 52 | QueryBuilder builder = match.buildQuery(); 53 | 54 | //Expectations 55 | String expected = "{\"match\":{\"colName\":{\"query\":\"value\",\"type\":\"boolean\",\"minimum_should_match\":\"100%\"}}}"; 56 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/functions/MultiMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.functions; 20 | 21 | import com.stratio.crossdata.common.data.ColumnName; 22 | import com.stratio.crossdata.common.data.TableName; 23 | import com.stratio.crossdata.common.exceptions.ExecutionException; 24 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 25 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 26 | import com.stratio.crossdata.common.statements.structures.FunctionRelation; 27 | import com.stratio.crossdata.common.statements.structures.Selector; 28 | import com.stratio.crossdata.common.statements.structures.StringSelector; 29 | import org.elasticsearch.index.query.QueryBuilder; 30 | import org.junit.Assert; 31 | import org.junit.Test; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | public class MultiMatchTest { 37 | 38 | 39 | @Test 40 | public void testMatch() throws UnsupportedException, ExecutionException { 41 | 42 | List parameters = new ArrayList<>(); 43 | TableName tableName = new TableName("catalog", "table"); 44 | parameters.add(new ColumnSelector(new ColumnName(tableName, "colName"))); 45 | parameters.add(new ColumnSelector(new ColumnName(tableName, "col2Name"))); 46 | parameters.add(new StringSelector("*_colName")); 47 | parameters.add(new StringSelector("value")); 48 | parameters.add(new StringSelector("1")); 49 | 50 | FunctionRelation function = new FunctionRelation(ESFunction.MULTI_MATCH, parameters,tableName); 51 | ESFunction match = ESFunction.build(function); 52 | 53 | //Experimentation 54 | QueryBuilder builder = match.buildQuery(); 55 | 56 | //Expectations 57 | String expected = "{\"multi_match\":{\"query\":\"value\",\"fields\":[\"colName\",\"col2Name\",\"*_colName\"],\"minimum_should_match\":\"1\"}}"; 58 | Assert.assertEquals(expected, builder.toString().replaceAll("\\s+", "")); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/query/metadata/MetadataCreatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.query.metadata; 20 | 21 | import com.stratio.connector.commons.engine.query.ProjectParsed; 22 | import com.stratio.connector.commons.engine.query.ProjectValidator; 23 | import com.stratio.connector.elasticsearch.core.engine.metadata.MetadataCreator; 24 | import com.stratio.crossdata.common.data.ClusterName; 25 | import com.stratio.crossdata.common.data.ColumnName; 26 | import com.stratio.crossdata.common.data.TableName; 27 | import com.stratio.crossdata.common.exceptions.ConnectorException; 28 | import com.stratio.crossdata.common.logicalplan.Project; 29 | import com.stratio.crossdata.common.logicalplan.Select; 30 | import com.stratio.crossdata.common.metadata.ColumnMetadata; 31 | import com.stratio.crossdata.common.metadata.ColumnType; 32 | import com.stratio.crossdata.common.metadata.DataType; 33 | import com.stratio.crossdata.common.metadata.Operations; 34 | import com.stratio.crossdata.common.statements.structures.ColumnSelector; 35 | import com.stratio.crossdata.common.statements.structures.Selector; 36 | import org.junit.After; 37 | import org.junit.Before; 38 | import org.junit.Test; 39 | 40 | import java.util.*; 41 | 42 | import static org.junit.Assert.assertEquals; 43 | import static org.mockito.Mockito.mock; 44 | 45 | /** 46 | * MetadataCreator Tester. 47 | * 48 | * @author 49 | * @version 1.0 50 | */ 51 | 52 | public class MetadataCreatorTest { 53 | 54 | private static final String CATALOG_NAME = "catalog_name"; 55 | private static final String TABLE_NAME = "table_name"; 56 | private static final String COLUMN_NAME1 = "column_name1"; 57 | private static final String ALIAS_1 = "alias_1"; 58 | 59 | private static final String COLUMN_NAME2 = "column_name2"; 60 | private static final String ALIAS_2 = "alias_2"; 61 | 62 | private static final String COLUMN_NAME3 = "column_name3"; 63 | private String[] NAMES = { COLUMN_NAME1, COLUMN_NAME2, COLUMN_NAME3 }; 64 | private static final String ALIAS_3 = "alias_3"; 65 | private String[] ALIAS = { ALIAS_1, ALIAS_2, ALIAS_3 }; 66 | MetadataCreator metadataCreator; 67 | 68 | 69 | private ColumnType[] TYPES = { new ColumnType(DataType.BOOLEAN), new ColumnType(DataType.DOUBLE), new ColumnType(DataType.VARCHAR) }; 70 | 71 | @Before 72 | public void before() throws Exception { 73 | 74 | metadataCreator = new MetadataCreator(); 75 | } 76 | 77 | @After 78 | public void after() throws Exception { 79 | } 80 | 81 | /** 82 | * Method: createColumnMetadata(ConnectorQueryData queryData) 83 | */ 84 | 85 | @Test 86 | public void testCreateMetadata() throws Exception { 87 | ProjectParsed queryData = createQueryData(); 88 | List columnMetadata = metadataCreator.createColumnMetadata(queryData); 89 | 90 | int i = 0; 91 | for (ColumnMetadata metadata : columnMetadata) { 92 | 93 | assertEquals("Alias is correct", ALIAS[i], metadata.getName().getAlias()); 94 | assertEquals("Column name is correct", CATALOG_NAME + "." + TABLE_NAME + "." + NAMES[i], metadata.getName() 95 | .getQualifiedName()); 96 | assertEquals("Table name is correct", CATALOG_NAME + "." + TABLE_NAME, metadata.getName().getTableName() 97 | .getQualifiedName()); 98 | assertEquals("Type name is correct", TYPES[i], metadata.getColumnType()); 99 | i++; 100 | 101 | } 102 | } 103 | 104 | private ProjectParsed createQueryData() throws ConnectorException { 105 | 106 | Map columnMap = new LinkedHashMap<>(); 107 | columnMap.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, NAMES[0])), ALIAS[0]); 108 | columnMap.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, NAMES[1])), ALIAS[1]); 109 | columnMap.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, NAMES[2])), ALIAS[2]); 110 | 111 | Map typeMap = new LinkedHashMap<>(); 112 | typeMap.put(ALIAS[0], TYPES[0]); 113 | typeMap.put(ALIAS[1], TYPES[1]); 114 | typeMap.put(ALIAS[2], TYPES[2]); 115 | 116 | Map typeColumnName = new LinkedHashMap<>(); 117 | typeColumnName.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, COLUMN_NAME1)), TYPES[0]); 118 | typeColumnName.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, COLUMN_NAME2)), TYPES[1]); 119 | typeColumnName.put(new ColumnSelector(new ColumnName(CATALOG_NAME, TABLE_NAME, COLUMN_NAME3)), TYPES[2]); 120 | 121 | Set operations = new HashSet<>(); 122 | operations.add(Operations.SELECT_OPERATOR); 123 | Select select = new Select(operations, columnMap, typeMap, typeColumnName); 124 | 125 | Set operations2 = new HashSet<>(); 126 | operations2.add(Operations.PROJECT); 127 | Project project = new Project(operations2, new TableName(CATALOG_NAME, TABLE_NAME), new ClusterName( 128 | "CLUSTER_NAME")); 129 | project.setNextStep(select); 130 | 131 | ProjectParsed queryData = new ProjectParsed(project, mock(ProjectValidator.class)); 132 | return queryData; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/utils/FilterBuilderCreatorTest.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.utils; 2 | 3 | import com.stratio.crossdata.common.data.ColumnName; 4 | import com.stratio.crossdata.common.data.TableName; 5 | import com.stratio.crossdata.common.exceptions.ExecutionException; 6 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 7 | import com.stratio.crossdata.common.logicalplan.Filter; 8 | import com.stratio.crossdata.common.metadata.Operations; 9 | import com.stratio.crossdata.common.statements.structures.*; 10 | import org.elasticsearch.index.query.FilterBuilder; 11 | import org.junit.Assert; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | 15 | import java.util.Arrays; 16 | import java.util.HashSet; 17 | 18 | /** 19 | * Created by lcisneros on 16/06/15. 20 | */ 21 | public class FilterBuilderCreatorTest { 22 | 23 | 24 | private FilterBuilderCreator filterBuilderCreator; 25 | 26 | @Before 27 | public void init(){ 28 | filterBuilderCreator = new FilterBuilderCreator(); 29 | } 30 | 31 | @Test 32 | public void testCreateFilterBuilderEq() throws UnsupportedException, ExecutionException { 33 | String expectations = "{\"bool\":{\"must\":{\"term\":{\"column\":10}}}}"; 34 | testCreateFilterBuilder(Operator.EQ, expectations); 35 | } 36 | 37 | @Test 38 | public void testCreateFilterBuilderDistinc() throws UnsupportedException, ExecutionException { 39 | String expectations = "{\"bool\":{\"must\":{\"not\":{\"filter\":{\"term\":{\"column\":10}}}}}}"; 40 | testCreateFilterBuilder(Operator.NOT_EQ, expectations); 41 | } 42 | 43 | @Test 44 | public void testCreateFilterBuilderLT() throws UnsupportedException, ExecutionException { 45 | String expectations = "{\"bool\":{\"must\":{\"range\":{\"column\":{\"from\":null,\"to\":10,\"include_lower\":true,\"include_upper\":false}}}}}"; 46 | testCreateFilterBuilder(Operator.LT, expectations); 47 | } 48 | 49 | @Test 50 | public void testCreateFilterBuilderLET() throws UnsupportedException, ExecutionException { 51 | String expectations = "{\"bool\":{\"must\":{\"range\":{\"column\":{\"from\":null,\"to\":10,\"include_lower\":true,\"include_upper\":true}}}}}"; 52 | testCreateFilterBuilder(Operator.LET, expectations); 53 | } 54 | 55 | @Test 56 | public void testCreateFilterBuilderGT() throws UnsupportedException, ExecutionException { 57 | String expectations = "{\"bool\":{\"must\":{\"range\":{\"column\":{\"from\":10,\"to\":null,\"include_lower\":false,\"include_upper\":true}}}}}"; 58 | testCreateFilterBuilder(Operator.GT, expectations); 59 | } 60 | 61 | @Test 62 | public void testCreateFilterBuilderGET() throws UnsupportedException, ExecutionException { 63 | String expectations = "{\"bool\":{\"must\":{\"range\":{\"column\":{\"from\":10,\"to\":null,\"include_lower\":true,\"include_upper\":true}}}}}"; 64 | testCreateFilterBuilder(Operator.GET, expectations); 65 | } 66 | 67 | @Test() 68 | public void testCreateFilterBuilderFail() throws UnsupportedException, ExecutionException { 69 | 70 | Selector from = new IntegerSelector (1); 71 | Selector to = new IntegerSelector (10); 72 | 73 | Selector left = new ColumnSelector(new ColumnName(new TableName("catalog", "table"), "column")); 74 | GroupSelector selector = new GroupSelector(new TableName("catalog", "table"),from, to); 75 | 76 | Relation relations = new Relation(left, Operator.BETWEEN, selector); 77 | 78 | Filter filter = new Filter(new HashSet<>(Arrays.asList(Operations.FILTER_FUNCTION_EQ)), relations); 79 | 80 | //Experimentation 81 | FilterBuilder result = filterBuilderCreator.createFilterBuilder(Arrays.asList(filter)); 82 | 83 | //Expectations 84 | String expected = "{\"bool\":{\"must\":{\"range\":{\"column\":{\"from\":1,\"to\":10,\"include_lower\":true,\"include_upper\":true}}}}}"; 85 | Assert.assertEquals(expected, result.toString().replace(" ", "").replace("\n", "")); 86 | } 87 | 88 | private void testCreateFilterBuilder(Operator operator, String expected) throws UnsupportedException, ExecutionException { 89 | 90 | Selector rigth = new IntegerSelector (10); 91 | Selector left = new ColumnSelector(new ColumnName(new TableName("catalog", "table"), "column")); 92 | 93 | Relation relations = new Relation(left, operator, rigth); 94 | 95 | Filter filter = new Filter(new HashSet<>(Arrays.asList(Operations.FILTER_FUNCTION_EQ)), relations); 96 | 97 | //Experimentation 98 | FilterBuilder result = filterBuilderCreator.createFilterBuilder(Arrays.asList(filter)); 99 | 100 | //Expectations 101 | Assert.assertEquals(expected, result.toString().replace(" ", "").replace("\n", "")); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/utils/IndexRequestBuilderCreatorExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.utils; 20 | 21 | import com.stratio.connector.commons.connection.Connection; 22 | import com.stratio.connector.elasticsearch.core.connection.ElasticSearchConnectionHandler; 23 | import com.stratio.crossdata.common.data.*; 24 | import com.stratio.crossdata.common.exceptions.ExecutionException; 25 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 26 | import com.stratio.crossdata.common.metadata.ColumnMetadata; 27 | import com.stratio.crossdata.common.metadata.IndexMetadata; 28 | import com.stratio.crossdata.common.metadata.TableMetadata; 29 | import com.stratio.crossdata.common.statements.structures.Selector; 30 | import org.elasticsearch.action.index.IndexRequestBuilder; 31 | import org.elasticsearch.client.Client; 32 | import org.junit.After; 33 | import org.junit.Before; 34 | import org.junit.Rule; 35 | import org.junit.Test; 36 | import org.junit.rules.ExpectedException; 37 | import org.mockito.Mock; 38 | 39 | import java.util.HashMap; 40 | import java.util.LinkedHashMap; 41 | import java.util.LinkedList; 42 | import java.util.Map; 43 | 44 | import static org.mockito.Mockito.when; 45 | import static org.powermock.api.mockito.PowerMockito.mock; 46 | 47 | /** 48 | * IndexRequestBuilderCreator Tester. 49 | * 50 | * @author 51 | * @version 1.0 52 | */ 53 | 54 | public class IndexRequestBuilderCreatorExceptionTest { 55 | 56 | private static final String CLUSTER_NAME = "CLUSTER NAME"; 57 | private static final String INDEX_NAME = "INDEX_NAME"; 58 | private static final String TYPE_NAME = "TYPE_NAME"; 59 | private TableName tableName = new TableName(INDEX_NAME, TYPE_NAME); 60 | private static final String ROW_NAME = "row_name"; 61 | private static final String OTHER_ROW_NAME = "OTHER_ROW_NAME"; 62 | private static final String CELL_VALUE = "cell_value"; 63 | 64 | @Rule 65 | public ExpectedException exception = ExpectedException.none(); 66 | IndexRequestBuilderCreator indexRequestBuilderCreator; 67 | private LinkedHashMap columns = new LinkedHashMap<>(); 68 | private Map options = new LinkedHashMap<>(); 69 | private Map indexes = new HashMap(); 70 | private ClusterName clusterRef = new ClusterName(CLUSTER_NAME); 71 | private LinkedList partitionKey = new LinkedList(); 72 | private LinkedList clusterKey = new LinkedList(); 73 | 74 | @Mock 75 | private ElasticSearchConnectionHandler connectionHandler; 76 | @Mock 77 | private Connection connection; 78 | @Mock 79 | private Client client; 80 | 81 | @Before 82 | public void before() throws Exception { 83 | 84 | client = mock(Client.class); 85 | indexRequestBuilderCreator = new IndexRequestBuilderCreator(); 86 | } 87 | 88 | @After 89 | public void after() throws Exception { 90 | } 91 | 92 | @Test 93 | public void testCreateIndesRequestTwoPK() throws UnsupportedException, ExecutionException { 94 | 95 | exception.expect(ExecutionException.class); 96 | exception.expectMessage("Only one PK is allowed"); 97 | 98 | partitionKey.add(new ColumnName(INDEX_NAME, TYPE_NAME, ROW_NAME)); 99 | partitionKey.add(new ColumnName(INDEX_NAME, TYPE_NAME, OTHER_ROW_NAME)); 100 | 101 | TableMetadata targetTable = new TableMetadata(tableName, options, columns, indexes, clusterRef, partitionKey, 102 | clusterKey); 103 | Row row = createRow(ROW_NAME, CELL_VALUE); 104 | row.addCell(OTHER_ROW_NAME, new Cell(CELL_VALUE)); 105 | 106 | IndexRequestBuilder indexRequestBuilder = mock(IndexRequestBuilder.class); 107 | when(indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row)).thenReturn( 108 | indexRequestBuilder); 109 | 110 | indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row); 111 | 112 | } 113 | 114 | private Row createRow(String rowKey, Object cellValue) { 115 | Cell cell = new Cell(cellValue); 116 | Row row = new Row(rowKey, cell); 117 | return row; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/utils/SelectorUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.stratio.connector.elasticsearch.core.engine.utils; 2 | 3 | 4 | import com.stratio.crossdata.common.data.ColumnName; 5 | import com.stratio.crossdata.common.statements.structures.FunctionSelector; 6 | import com.stratio.crossdata.common.statements.structures.SelectExpression; 7 | import com.stratio.crossdata.common.statements.structures.Selector; 8 | import org.junit.Test; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertNull; 15 | import static org.mockito.Mockito.mock; 16 | import static org.mockito.Mockito.when; 17 | 18 | public class SelectorUtilsTest { 19 | 20 | @Test 21 | public void testGetNullSelectorFieldName(){ 22 | assertNull(SelectorUtils.getSelectorFieldName(null)); 23 | } 24 | 25 | @Test 26 | public void testGetSelectorFieldName(){ 27 | Selector selector = mock(Selector.class); 28 | ColumnName columnName = mock(ColumnName.class); 29 | when(selector.getColumnName()).thenReturn(columnName); 30 | when(columnName.getName()).thenReturn("fieldName"); 31 | 32 | assertEquals("fieldName", SelectorUtils.getSelectorFieldName(selector)); 33 | } 34 | 35 | @Test 36 | public void testGetSelectorUnknownFunctionName(){ 37 | FunctionSelector functionSelector = mock(FunctionSelector.class); 38 | List functionColumns = new ArrayList(); 39 | Selector selector = mock(Selector.class); 40 | ColumnName columnName = mock(ColumnName.class); 41 | Selector analyzer = mock(Selector.class); 42 | functionColumns.add(selector); 43 | functionColumns.add(analyzer); 44 | SelectExpression se = mock(SelectExpression.class); 45 | 46 | when(functionSelector.getFunctionName()).thenReturn("unknown"); 47 | when(functionSelector.getFunctionColumns()).thenReturn(se); 48 | when(se.getSelectorList()).thenReturn(functionColumns); 49 | when(selector.getColumnName()).thenReturn(columnName); 50 | when(columnName.getName()).thenReturn("fieldName"); 51 | when(analyzer.getStringValue()).thenReturn("analyzer"); 52 | 53 | assertEquals("unknown", SelectorUtils.getSelectorFieldName(functionSelector)); 54 | } 55 | 56 | @Test 57 | public void testGetSelectorFunctionSubFieldName(){ 58 | FunctionSelector functionSelector = mock(FunctionSelector.class); 59 | List functionColumns = new ArrayList(); 60 | Selector selector = mock(Selector.class); 61 | ColumnName columnName = mock(ColumnName.class); 62 | Selector analyzer = mock(Selector.class); 63 | functionColumns.add(selector); 64 | functionColumns.add(analyzer); 65 | SelectExpression se = mock(SelectExpression.class); 66 | 67 | when(functionSelector.getFunctionName()).thenReturn("sub_field"); 68 | when(functionSelector.getFunctionColumns()).thenReturn(se); 69 | when(functionSelector.getFunctionColumns().getSelectorList()).thenReturn(functionColumns); 70 | when(selector.getColumnName()).thenReturn(columnName); 71 | when(columnName.getName()).thenReturn("fieldName"); 72 | when(analyzer.getStringValue()).thenReturn("analyzer"); 73 | 74 | assertEquals("fieldName.analyzer", SelectorUtils.getSelectorFieldName(functionSelector)); 75 | } 76 | } -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/java/com/stratio/connector/elasticsearch/core/engine/utils/TypeConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to STRATIO (C) under one or more contributor license agreements. 3 | * See the NOTICE file distributed with this work for additional information 4 | * regarding copyright ownership. The STRATIO (C) licenses this file 5 | * to you under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance 7 | * with the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package com.stratio.connector.elasticsearch.core.engine.utils; 20 | 21 | import com.stratio.crossdata.common.exceptions.ExecutionException; 22 | import com.stratio.crossdata.common.exceptions.UnsupportedException; 23 | import com.stratio.crossdata.common.metadata.ColumnType; 24 | import com.stratio.crossdata.common.metadata.DataType; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | import java.util.HashMap; 29 | import java.util.LinkedList; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | import static org.junit.Assert.fail; 35 | 36 | /** 37 | * TypeConverter Tester. 38 | * 39 | * @author 40 | * @version 1.0 41 | */ 42 | public class TypeConverterTest { 43 | 44 | /** 45 | * Method: convert(ColumnType columnType) 46 | */ 47 | 48 | private Map convet = new HashMap<>(); 49 | 50 | private List exceptions = new LinkedList<>(); 51 | 52 | @Before 53 | public void setUp() { 54 | convet.put(new ColumnType(DataType.BOOLEAN), "boolean"); 55 | convet.put(new ColumnType(DataType.BIGINT), "long"); 56 | convet.put(new ColumnType(DataType.DOUBLE), "double"); 57 | convet.put(new ColumnType(DataType.FLOAT), "float"); 58 | convet.put(new ColumnType(DataType.INT), "integer"); 59 | convet.put(new ColumnType(DataType.TEXT), "string"); 60 | convet.put(new ColumnType(DataType.VARCHAR), "string"); 61 | ColumnType listType = new ColumnType(DataType.LIST, null); 62 | listType.setDBCollectionType(new ColumnType(DataType.TEXT)); 63 | convet.put(listType, "string"); 64 | 65 | exceptions.add(new ColumnType(DataType.MAP)); 66 | exceptions.add(new ColumnType(DataType.NATIVE)); 67 | exceptions.add(new ColumnType(DataType.SET)); 68 | 69 | } 70 | 71 | @Test 72 | public void testConvert() throws Exception { 73 | 74 | allCoveredTest(); 75 | conversionTest(); 76 | exceptionTest(); 77 | 78 | } 79 | 80 | private void allCoveredTest() { 81 | assertEquals("All features are tested", DataType.values().length, convet.size() + exceptions.size()); 82 | } 83 | 84 | private void conversionTest() throws UnsupportedException, ExecutionException { 85 | for (Map.Entry convertedTypes : convet.entrySet()) { 86 | assertEquals("The conversion is correct", convertedTypes.getValue(), 87 | TypeConverter.convert(convertedTypes.getKey())); 88 | } 89 | } 90 | 91 | private void exceptionTest() { 92 | for (ColumnType columnType : exceptions) { 93 | try { 94 | TypeConverter.convert(columnType); 95 | } catch (ExecutionException e) { 96 | continue; 97 | } 98 | fail("The execution musn't are here with this column type " + columnType); 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/resources/ElasticSearchConnector.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | elasticsearch 22 | 23 | elasticsearch 24 | 25 | 26 | 0.1.0 27 | 28 | 29 | 30 | node_type 31 | If the connection is Node or Transport 32 | 33 | 34 | 35 | PROJECT 36 | CREATE_CATALOG 37 | DROP_CATALOG 38 | CREATE_TABLE 39 | DROP_TABLE 40 | INSERT 41 | SELECT_OPERATOR 42 | FILTER_PK_EQ 43 | FILTER_PK_GT 44 | FILTER_PK_LT 45 | FILTER_PK_GET 46 | FILTER_PK_LET 47 | FILTER_PK_NOT_EQ 48 | FILTER_INDEXED_EQ 49 | FILTER_INDEXED_GT 50 | FILTER_INDEXED_LT 51 | FILTER_INDEXED_GET 52 | FILTER_INDEXED_LET 53 | FILTER_INDEXED_NOT_EQ 54 | FILTER_FULLTEXT 55 | 56 | 57 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/resources/ElasticSearchDataStore.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 | elasticsearch 24 | 0.4.0 25 | 26 | 27 | Hosts 28 | The list of hosts ips 29 | 30 | 31 | Port 32 | The list of hosts ports 33 | 34 | 35 | 36 | ALL_INDEXED 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /connector-elasticsearch/src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 23 | 24 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 23 | 4.0.0 24 | com.stratio.connector 25 | stratio-connector-elasticsearch-doc 26 | http://www.stratio.com 27 | Stratio ElasticSearch Connector documentation 28 | Stratio Crossdata connector for ElasticSearch documentation 29 | 30 | 31 | com.stratio.connector 32 | stratio-connector-elasticsearch 33 | 0.5.5-RC1-SNAPSHOT 34 | 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-site-plugin 40 | 3.4 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-project-info-reports-plugin 46 | 2.8 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | com.stratio.maven 55 | sphinx-maven-plugin 56 | 2.0.0 57 | 58 | 59 | html 60 | 61 | 62 | 63 | src/site/sphinx 64 | true 65 | 66 | conf.py 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /doc/src/site/sphinx/0_concepts.rst: -------------------------------------------------------------------------------- 1 | CONCEPTS 2 | ******** 3 | 4 | Settings and Analyzers 5 | ---------------------- 6 | 7 | Elasticsearch index behaviour can be customized via settings 8 | `properties `_. 9 | We can set these properties during the catalog creation using the option 10 | "settings" including the configuration as a json string. This way we can 11 | set properties like the number of shards and replicas and even define 12 | new `analyzers `_. 13 | 14 | 15 | :: 16 | 17 | CREATE CATALOG movies WITH {'settings' : '{"number_of_replicas" : "0","number_of_shards" : "1","analysis" : {"analyzer" : {"raw" : 18 | {"tokenizer" : "keyword"},"normalized" : {"filter" : ["lowercase"],"tokenizer" : "keyword"},"english" : {"filter" : ["lowercase", 19 | "english_stemmer"],"tokenizer" : "standard"}},"filter" : {"english_stemmer" : {"type" : "stemmer","language" : "english"}}}}'}; 20 | 21 | In this example we are configuring three analyzers appart from the 22 | standard ones: 23 | 24 | - **raw**: Does not tokenize nor change the original nor lowercases it. 25 | Suitable for groupings and aggregations if the fields are case 26 | sensitive. 27 | - **normalized**: Lowercases the input but does not tokenize it. 28 | Suitable for sorting (and groupings and aggregations if fields are 29 | not case sensitive). 30 | - **english**: Applies the same transformations than the standard 31 | analyzer and applies english stemming to the resulting tokens. 32 | Suitable for searching through english texts. 33 | 34 | Take into account that this is an advanced functionality that requires 35 | some elasticsearch knowledge, if you just want to use the basic search 36 | you can just create the catalog with no options. 37 | 38 | SubFields 39 | --------- 40 | 41 | Elasticsearch allows us to define subfields by applying different 42 | analyzers to the original field. Those fields may be used for specific 43 | functionalities like sorting the results, getting aggregations or even 44 | achieving a better search experience by applying, for example, language 45 | specific rules. 46 | 47 | Defining SubFields 48 | ------------------ 49 | 50 | Those subfields can be defined through the mappings configuration and 51 | once the subfields had been set, the subfields associated to each field 52 | would be generated automatically each time a new document is inserted. 53 | In order to create this mapping configuration we just have to specify 54 | the analyzers that will apply to each field during the table creation, 55 | and the appropriate configuration will be generated. Keep in mind that, 56 | these subfields can only be set for text fields and that, for analyzers 57 | different from the standard ones you should define them through the 58 | settings property during catalog creation. The standard analyzer is 59 | always applied to the original field unless it is specified as 60 | "not\_analyzed", therefore even if no subfield is defined we could have 61 | at least a basic analysis applied to our text fields. Standard analyzer 62 | tokenizes the input by whitespaces and other punctuation symbols and 63 | lowercases the resulting tokens being suitable for generic language 64 | texts. 65 | 66 | :: 67 | 68 | CREATE TABLE movie ON CLUSTER elasticsearch_cluster (id text("index":"not_analyzed") PRIMARY KEY, title text("analyzer":"english", 69 | "analyzer":"normalized", "analyzer":"raw"), released boolean); 70 | 71 | In this example we are creating three additional subfields associated to 72 | the field "title", therefore we will have the original field "title" 73 | using standard analyzer, and the subfields "title.raw", 74 | "title.normalized" and "title.english" using the associated analyzers. 75 | 76 | Using SubFields 77 | --------------- 78 | 79 | In order to work with those subfields we can use the "SUB\_FIELD" 80 | function or the subfield notation depending on whether we are using them 81 | inside a function or not: 82 | 83 | - **Outside a function**: We must call the "SUB\_FIELD" function 84 | passing the field name as the first parameter and the name of the 85 | analyzer as the second one. (e.g. "sub\_field(field, "analyzer")" 86 | - **Inside a fuction**: We must use the subfield notation being "{field 87 | name}.{analyzer}" (e.g. "function(field.analizer)") -------------------------------------------------------------------------------- /doc/src/site/sphinx/1_functions.rst: -------------------------------------------------------------------------------- 1 | FUNCTIONS 2 | ********* 3 | 4 | CONTAINS 5 | -------- 6 | 7 | Contains function allows to search a text inside one ormore fields. 8 | 9 | **contains (fields, value, minimumShouldMatch)** 10 | 11 | \* **fields:** Field or fields to be searched in. Multiple fields can be 12 | specified separated by whitespaces. Those fields can be configured 13 | individually using the notation "field^boost" in order to boost those 14 | documents where the searched terms appear in the fields with higher 15 | boosting values. \* **value:** Text to be searched. \* 16 | **minimumShouldMatch:** For multiterm values indicates the number of 17 | matches that a document must include in order to be retrieved as a 18 | result for the query. It can be expressed either as an absolute number 19 | of terms or as a percentage (Negative values indicates missing number of 20 | terms or percentage from total). 21 | 22 | Example: 23 | 24 | :: 25 | 26 | SELECT title FROM movie WHERE contains("title.english", "lord 27 | rings", "100%"); SELECT title FROM movie WHERE 28 | contains("title.english title^10", "lords", "100%"); 29 | 30 | FUZZY 31 | ------ 32 | 33 | Fuzzy function uses distance algorithms to find results including terms similar to those indicated. 34 | 35 | **fuzzy (fields, value, fuzziness)** 36 | 37 | - **fields:** Field or fields to be searched in (Equivalent to the 38 | "fields" parameter in contains function). 39 | - **value:** Text to be searched. 40 | 41 | \* **fuzzines:** Number indicating the maximum [edit distance] 42 | (https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness) 43 | to consider a term similar to another. 44 | 45 | Example: 46 | 47 | :: 48 | 49 | SELECT title FROM movie WHERE fuzzy("title.english", "lorz", "0.6"); 50 | SELECT title FROM movie WHERE multi\_match\_fuzzy("title.english 51 | title^10", "lorzs", "0.6"); 52 | 53 | MATCH PHRASE 54 | ------------- 55 | 56 | Match Phrase function searches multiterm values as a phrase, meaning that terms must be found in the exact same order to be 57 | considered as a match. 58 | 59 | **match\_phrase (field, phrase)** 60 | 61 | - **field:** Field to be searched in. 62 | - **phrase:** Text to be searched. 63 | 64 | Example: 65 | 66 | :: 67 | 68 | SELECT title FROM movie WHERE match\_phrase("title", "lord of the 69 | rings"); 70 | 71 | MATCH PREFIX 72 | ------------ 73 | 74 | Match Prefix function searches for documents including terms starting for the given prefix. 75 | 76 | **match\_prefix (field, prefix)** 77 | 78 | - **field:** Field to be searched in. 79 | - **prefix:** Prefix to be searched. 80 | 81 | Example: 82 | 83 | :: 84 | 85 | SELECT title FROM movie WHERE match\_prefix("title", "lor"); -------------------------------------------------------------------------------- /doc/src/site/sphinx/2_examples.rst: -------------------------------------------------------------------------------- 1 | EXAMPLES 2 | -------- 3 | 4 | Retrieving every document: 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | 7 | :: 8 | 9 | SELECT * FROM movie; 10 | 11 | Counting results: 12 | ~~~~~~~~~~~~~~~~~ 13 | 14 | :: 15 | 16 | SELECT count(*) FROM movie; 17 | 18 | Retrieving specific fields: 19 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20 | 21 | :: 22 | 23 | SELECT title,metascore FROM movie; 24 | 25 | Retrieving specific subfield: 26 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 | 28 | :: 29 | 30 | SELECT SUB_FIELD(title,"raw") AS title_raw FROM movie; 31 | 32 | *Though during operations the different analyzers cause different 33 | behaviours the results always show the original input, therefore it 34 | would make no difference if a field or any subfield is retrieved instead 35 | via SELECT, the result would be the same. If using subfields in the 36 | select clause it is recommended to assign an alias for the sake of 37 | readability.* 38 | 39 | Limiting number of retrieved documents: 40 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41 | 42 | :: 43 | 44 | SELECT title FROM movie LIMIT 5; 45 | 46 | Sorting results: 47 | ~~~~~~~~~~~~~~~~ 48 | 49 | :: 50 | 51 | SELECT title,metascore FROM movie ORDER BY metascore DESC; 52 | SELECT title,metascore FROM movie ORDER BY metascore ASC; 53 | 54 | Sorting results by subfield: 55 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | 57 | :: 58 | 59 | SELECT title FROM movie ORDER BY sub_field(title, "normalized") DESC; 60 | 61 | Querying data: 62 | ~~~~~~~~~~~~~~ 63 | 64 | **Searching** (Calculates relevance of results): 65 | 66 | :: 67 | 68 | SELECT title FROM movie WHERE contains("title.english", "lord ring", "100%"); 69 | 70 | **Filtering** (Does not calculate relevance): 71 | 72 | :: 73 | 74 | SELECT title,year FROM movie WHERE year=2000; 75 | 76 | Grouping by field: 77 | ~~~~~~~~~~~~~~~~~~ 78 | 79 | :: 80 | 81 | SELECT rated, count(*) FROM movie GROUP BY rated; 82 | 83 | Grouping by subfield: 84 | ~~~~~~~~~~~~~~~~~~~~~ 85 | 86 | :: 87 | 88 | SELECT sub_field(genre,"raw") AS genre, count(*) FROM movie GROUP BY sub_field(genre,"raw"); 89 | 90 | *This is the only case where it does matter using a subfield as select 91 | instead of the original field, as the select field must be the same as 92 | the one used in the group by clause and the results will be displayed 93 | transformed by the analyzer.* 94 | 95 | Nested grouping: 96 | ~~~~~~~~~~~~~~~~ 97 | 98 | :: 99 | 100 | SELECT sub_field(genre,"raw") AS genre, rated, count(*) FROM movie GROUP BY sub_field(genre,"raw"), rated; 101 | 102 | Other examples: 103 | ~~~~~~~~~~~~~~~ 104 | 105 | **Documents of type "movie" their year greater or equal to 1950:** 106 | 107 | :: 108 | 109 | SELECT title,year FROM movie WHERE type = "movie" and year>=1950 and year<=2010; 110 | 111 | **Ordering the results by year in descending order:** 112 | 113 | :: 114 | 115 | SELECT title,year FROM movie WHERE type = "movie" and year>=1950 and year<=2010 ORDER BY year DESC; 116 | 117 | **Limiting the results to those including the word "lord" in their 118 | title:** 119 | 120 | :: 121 | 122 | SELECT title,year FROM movie WHERE contains("title.english", "lord", "100%") and type = "movie" and year>=1950 and year<=2010 ORDER BY year DESC; 123 | 124 | **Searching "lord" in both title and plot:** 125 | 126 | :: 127 | 128 | SELECT title,year FROM movie WHERE contains("title.english plot.english", "lord", "100%") and type = "movie" and year>=1950 and year<=2010 ORDER BY year DESC; 129 | 130 | **Searching actors similar to the term "elija":** 131 | 132 | :: 133 | 134 | SELECT title,year,actors FROM movie WHERE contains("title.english plot.english", "lord", "100%") AND fuzzy("actors","elija","0.6") and type = "movie" and year>=1950 and year<=2010 ORDER BY year DESC; 135 | 136 | **Searching for both "lord" or "sun" in title and plot instead of just 137 | "lord":** 138 | 139 | :: 140 | 141 | SELECT title,year,actors FROM movie WHERE contains("title.english plot.english", "lord sun", "50%") AND fuzzy("actors","elija","0.6") and type = "movie" and year>=1950 and year<=2015 ORDER BY year DESC; -------------------------------------------------------------------------------- /doc/src/site/sphinx/about.rst: -------------------------------------------------------------------------------- 1 | About 2 | ***** 3 | 4 | Stratio Connector Elasticsearch is a crossdata connector interface 5 | implementation for elasticsearch 1.7.1. 6 | 7 | Requirements 8 | ------------ 9 | 10 | Install `elasticsearch 1.7.1 `_ and run it. 11 | `Crossdata `_ is needed to interact with this 12 | connector. 13 | 14 | Compiling an building an executable Stratio Connector Elasticsearch 15 | ------------------------------------------------------------------- 16 | 17 | To automatically build execute the following command: 18 | 19 | :: 20 | 21 | > mvn clean install 22 | 23 | Running the Stratio Connector Elasticsearch 24 | ------------------------------------------- 25 | 26 | To run Connector Elasticsearch execute: 27 | 28 | :: 29 | 30 | > ./connector-elasticsearch/target/stratio-connector-elasticsearch/bin/stratio-connector-elasticsearch 31 | 32 | 33 | 34 | Build a redistributable package 35 | ------------------------------- 36 | It is possible too, to create a RPM or DEB redistributable package. 37 | 38 | 39 | :: 40 | 41 | > mvn package -Ppackage 42 | 43 | 44 | Once the package it's created, execute this commands to install: 45 | 46 | RPM Package: 47 | 48 | :: 49 | 50 | > rpm -i target/stratio-connector-elasticsearch-.rpm 51 | 52 | DEB Package: 53 | 54 | :: 55 | 56 | > dpkg -i target/stratio-connector-elasticsearch-.deb 57 | 58 | Now to start/stop the connector: 59 | 60 | :: 61 | 62 | > service connector-elasticsearch start 63 | > service connector-elasticsearch stop 64 | 65 | How to use Elasticsearch Connector 66 | ---------------------------------- 67 | 68 | A complete tutorial is available `here `__. The basic commands are described below. 69 | 70 | 1. Start `crossdata-server and then 71 | crossdata-shell `__. 72 | 2. Start Elasticsearch Connector as it is explained before 73 | 3. In crossdata-shell: 74 | 75 | Attach cluster on that datastore. The datastore name must be the same 76 | as the defined in the Datastore manifest. 77 | 78 | :: 79 | 80 | xdsh:user> ATTACH CLUSTER ON DATASTORE WITH OPTIONS {'Hosts': '[]', 'Port': '[]'}; 81 | 82 | Attach the connector to the previously defined cluster. The connector 83 | name must match the one defined in the Connector Manifest, and the 84 | cluster name must match with the previously defined in the ATTACH 85 | CLUSTER command. 86 | 87 | :: 88 | 89 | xdsh:user> ATTACH CONNECTOR TO WITH OPTIONS {}; 90 | 91 | At this point, we can start to send queries, that Crossdata execute 92 | with the connector specified. 93 | 94 | :: 95 | 96 | xdsh:user> CREATE CATALOG catalogTest; 97 | 98 | xdsh:user> USE catalogTest; 99 | 100 | xdsh:user> CREATE TABLE tableTest ON CLUSTER (id int PRIMARY KEY, name text); 101 | 102 | xdsh:user> INSERT INTO tableTest(id, name) VALUES (1, 'stratio'); 103 | 104 | xdsh:user> SELECT * FROM tableTest; 105 | 106 | 107 | License 108 | ======= 109 | 110 | Licensed to STRATIO (C) under one or more contributor license 111 | agreements. See the NOTICE file distributed with this work for 112 | additional information regarding copyright ownership. The STRATIO (C) 113 | licenses this file to you under the Apache License, Version 2.0 (the 114 | "License"); you may not use this file except in compliance with the 115 | License. You may obtain a copy of the License at 116 | 117 | http://www.apache.org/licenses/LICENSE-2.0 118 | 119 | Unless required by applicable law or agreed to in writing, software 120 | distributed under the License is distributed on an "AS IS" BASIS, 121 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122 | See the License for the specific language governing permissions and 123 | limitations under the License. 124 | 125 | -------------------------------------------------------------------------------- /doc/src/site/sphinx/index.rst: -------------------------------------------------------------------------------- 1 | Contents: 2 | ******** 3 | .. toctree:: 4 | :maxdepth: 5 5 | :numbered: 6 | 7 | about.rst 8 | First_Steps.rst 9 | 0_concepts.rst 10 | 1_functions.rst 11 | 2_examples.rst -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 24 | 4.0.0 25 | com.stratio.connector 26 | stratio-connector-elasticsearch 27 | 0.5.5-RC1-SNAPSHOT 28 | http://www.stratio.com 29 | Stratio ElasticSearch Connector 30 | Stratio Crossdata connector for ElasticSearch 31 | pom 32 | 33 | com.stratio 34 | parent 35 | 0.5.0 36 | 37 | 38 | 0.6.4 39 | 1.7.1 40 | UTF-8 41 | UTF-8 42 | 7190 43 | 44 | 45 | 46 | Apache License, Version 2.0 47 | http://www.apache.org/licenses/LICENSE-2.0t 48 | repo 49 | 50 | 51 | 52 | doc 53 | connector-elasticsearch 54 | 55 | 56 | scm:git:git@github.com:Stratio/stratio-connector-elasticsearch.git 57 | scm:git:git@github.com:Stratio/stratio-connector-elasticsearch.git 58 | https://github.com/Stratio/stratio-connector-elasticsearch 59 | 60 | 61 | 62 | jmgomez 63 | Jose Manuel Gómez 64 | jmgomez@stratio.com 65 | 66 | architect 67 | developer 68 | maintainer 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-compiler-plugin 77 | 3.1 78 | 79 | 1.7 80 | 1.7 81 | 82 | 83 | 84 | 85 | 86 | --------------------------------------------------------------------------------