Skip to content

Commit

Permalink
fix build issue
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <[email protected]>
  • Loading branch information
penghuo committed Nov 17, 2022
1 parent 738020f commit e459ea7
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 23 deletions.
19 changes: 11 additions & 8 deletions core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
import org.opensearch.sql.ast.tree.TableFunction;
import org.opensearch.sql.ast.tree.UnresolvedPlan;
import org.opensearch.sql.ast.tree.Values;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.data.model.ExprMissingValue;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.Expression;
Expand Down Expand Up @@ -147,12 +147,15 @@ public LogicalPlan visitRelation(Relation node, AnalysisContext context) {
if (CATALOGS_TABLE_NAME.equals(tableName)) {
table = new DataSourceTable(dataSourceService);
} else {
table = dataSourceService
.getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName())
.getStorageEngine()
.getTable(new CatalogSchemaName(dataSourceSchemaIdentifierNameResolver.getDataSourceName(),
dataSourceSchemaIdentifierNameResolver.getSchemaName()),
dataSourceSchemaIdentifierNameResolver.getIdentifierName());
table =
dataSourceService
.getDataSource(dataSourceSchemaIdentifierNameResolver.getDataSourceName())
.getStorageEngine()
.getTable(
new CatalogSchemaName(
dataSourceSchemaIdentifierNameResolver.getDataSourceName(),
dataSourceSchemaIdentifierNameResolver.getSchemaName()),
dataSourceSchemaIdentifierNameResolver.getIdentifierName());
}
table.getFieldTypes().forEach((k, v) -> curEnv.define(new Symbol(Namespace.FIELD_NAME, k), v));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class DataSourceServiceImpl implements DataSourceService {

private static String CATALOG_NAME_REGEX = "[@*A-Za-z]+?[*a-zA-Z_\\-0-9]*";
private static String DATASOURCE_NAME_REGEX = "[@*A-Za-z]+?[*a-zA-Z_\\-0-9]*";

private static final Logger LOG = LogManager.getLogger();

Expand Down Expand Up @@ -79,7 +79,7 @@ private void validateDataSource(DataSourceMetadata metadata) {
throw new IllegalArgumentException(
"Missing Name Field from a DataSource. Name is a required parameter.");
}
if (!metadata.getName().matches(CATALOG_NAME_REGEX)) {
if (!metadata.getName().matches(DATASOURCE_NAME_REGEX)) {
throw new IllegalArgumentException(
String.format(
"DataSource Name: %s contains illegal characters. Allowed characters: a-zA-Z0-9_-*@.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.planner.DefaultImplementor;
import org.opensearch.sql.planner.logical.LogicalPlan;
import org.opensearch.sql.planner.logical.LogicalRelation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.data.model.ExprTupleValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.model.ExprValueUtils;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.storage.TableScanOperator;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.opensearch.sql.analysis.symbol.Symbol;
import org.opensearch.sql.analysis.symbol.SymbolTable;
import org.opensearch.sql.ast.tree.UnresolvedPlan;
import org.opensearch.sql.config.TestConfig;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.config.TestConfig;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.exception.ExpressionEvaluationException;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.Expression;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.datasource.model.auth;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;

class AuthenticationTypeTest {
@Test
void getAuthType() {
assertEquals(
AuthenticationType.BASICAUTH,
AuthenticationType.get(AuthenticationType.BASICAUTH.getName()));
assertEquals(
AuthenticationType.AWSSIGV4AUTH,
AuthenticationType.get(AuthenticationType.AWSSIGV4AUTH.getName()));
}

@Test
void getNotExistAuthType() {
assertNull(AuthenticationType.get("mock"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.data.model.ExprTupleValue;
import org.opensearch.sql.data.model.ExprValueUtils;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.data.model.ExprTupleValue;
import org.opensearch.sql.data.model.ExprValueUtils;
import org.opensearch.sql.storage.StorageEngine;

@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.planner.logical.LogicalPlanDSL;
import org.opensearch.sql.planner.physical.PhysicalPlan;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package org.opensearch.sql.opensearch.storage;

import lombok.RequiredArgsConstructor;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.opensearch.client.OpenSearchClient;
import org.opensearch.sql.storage.DataSourceFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.opensearch.storage;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.opensearch.client.OpenSearchClient;

@ExtendWith(MockitoExtension.class)
class OpenSearchDataSourceFactoryTest {

@Mock private OpenSearchClient client;

@Mock private Settings settings;

@Mock private DataSourceMetadata dataSourceMetadata;

private OpenSearchDataSourceFactory factory;

@BeforeEach
public void setup() {
factory = new OpenSearchDataSourceFactory(client, settings);
}

@Test
void getDataSourceType() {
assertEquals(DataSourceType.OPENSEARCH, factory.getDataSourceType());
}

@Test
void createDataSource() {
when(dataSourceMetadata.getName()).thenReturn("opensearch");

DataSource dataSource = factory.createDataSource(dataSourceMetadata);
assertEquals("opensearch", dataSource.getName());
assertEquals(DataSourceType.OPENSEARCH, dataSource.getConnectorType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class OpenSearchStorageEngineTest {
@Test
public void getTable() {
OpenSearchStorageEngine engine = new OpenSearchStorageEngine(client, settings);
Table table = engine.getTable(new CatalogSchemaName(DEFAULT_DATASOURCE_NAME, "default"), "test");
Table table =
engine.getTable(new CatalogSchemaName(DEFAULT_DATASOURCE_NAME, "default"), "test");
assertNotNull(table);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.common.response.ResponseListener;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.executor.DefaultQueryManager;
import org.opensearch.sql.executor.ExecutionEngine;
import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.opensearch.sql.prometheus.authinterceptors.BasicAuthenticationInterceptor;
import org.opensearch.sql.prometheus.client.PrometheusClient;
import org.opensearch.sql.prometheus.client.PrometheusClientImpl;
import org.opensearch.sql.storage.StorageEngine;
import org.opensearch.sql.storage.DataSourceFactory;
import org.opensearch.sql.storage.StorageEngine;

public class PrometheusStorageFactory implements DataSourceFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.storage.StorageEngine;

Expand All @@ -22,7 +24,8 @@ public class PrometheusStorageFactoryTest {
@Test
void testGetConnectorType() {
PrometheusStorageFactory prometheusStorageFactory = new PrometheusStorageFactory();
Assertions.assertEquals(DataSourceType.PROMETHEUS, prometheusStorageFactory.getDataSourceType());
Assertions.assertEquals(
DataSourceType.PROMETHEUS, prometheusStorageFactory.getDataSourceType());
}

@Test
Expand Down Expand Up @@ -130,6 +133,21 @@ void testGetStorageEngineWithInvalidURISyntax() {
exception.getMessage().contains("Prometheus Client creation failed due to:"));
}

@Test
void createDataSourceSuccess() {
HashMap<String, String> properties = new HashMap<>();
properties.put("prometheus.uri", "http://dummyprometheus:9090");
properties.put("prometheus.auth.type", "basicauth");
properties.put("prometheus.auth.username", "admin");
properties.put("prometheus.auth.password", "admin");

DataSourceMetadata metadata = new DataSourceMetadata();
metadata.setName("prometheus");
metadata.setConnector(DataSourceType.PROMETHEUS);
metadata.setProperties(properties);

DataSource dataSource = new PrometheusStorageFactory().createDataSource(metadata);
Assertions.assertTrue(dataSource.getStorageEngine() instanceof PrometheusStorageEngine);
}
}

0 comments on commit e459ea7

Please sign in to comment.