Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Upgrade OS Version to 2.0.0-alpha1-SNAPSHOT #518

Merged
merged 5 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/sql-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: SQL Java CI

on: [push, pull_request]

env:
OPENSEARCH_VERSION: '2.0.0-SNAPSHOT'
joshuali925 marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
strategy:
Expand All @@ -24,7 +21,7 @@ jobs:
java-version: ${{ matrix.java }}

- name: Build with Gradle
run: ./gradlew build assemble -Dopensearch.version=${{ env.OPENSEARCH_VERSION }}
run: ./gradlew build assemble

- name: Run backward compatibility tests
run: ./bwctest.sh
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "2.0.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "2.0.0-alpha1-SNAPSHOT")
}

repositories {
Expand Down Expand Up @@ -37,10 +37,15 @@ repositories {

ext {
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersionQualifier = System.getProperty("build.version_qualifier", "alpha1")
}

allprojects {
version = opensearch_version - "-SNAPSHOT" + ".0"
version = opensearch_version.tokenize('-')[0] + '.0'
if (buildVersionQualifier) {
version += "-${buildVersionQualifier}"
}

if (isSnapshot) {
version += "-SNAPSHOT"
}
Expand Down
2 changes: 1 addition & 1 deletion bwctest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function setup_bwc_artifact() {
# then converts to plugin version by appending ".0" (e.g. 1.2.0.0-SNAPSHOT),
# assuming one line in build.gradle is 'opensearch_version= System.getProperty("opensearch.version", "<opensearch_version>")'.
plugin_version=$(grep 'opensearch_version = System.getProperty' build.gradle | \
grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+[^"]*' | sed -e 's/\([0-9]\)\([^0-9]*\)$/\1.0\2/')
grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+[^"]*' | sed -e 's/\(.*\)\(\.[0-9]\)/\1\2.0/')
plugin_artifact="./plugin/build/distributions/opensearch-sql-$plugin_version.zip"
bwc_artifact_dir="./integ-test/src/test/resources/bwc/$plugin_version"

Expand Down
5 changes: 3 additions & 2 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ configurations.all {
// enforce 1.1.3, https://www.whitesourcesoftware.com/vulnerability-database/WS-2019-0379
resolutionStrategy.force 'commons-codec:commons-codec:1.13'
resolutionStrategy.force 'com.google.guava:guava:31.0.1-jre'
resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-core:2.12.6'
resolutionStrategy.force 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.12.6'
resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-core:2.13.2'
resolutionStrategy.force 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.13.2'
vmmusings marked this conversation as resolved.
Show resolved Hide resolved
resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void bothTableAliasNoCommonColumns() throws IOException {
}

@Test
@Ignore
public void tableNamesWithTypeName() throws IOException {
sameExplain(
query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ public void dateSearchBraces() throws IOException {

JSONObject response = executeQuery(
String.format(Locale.ROOT,
"SELECT odbc_time FROM %s/odbc WHERE odbc_time < {ts '2015-03-15 00:00:00.000'}",
"SELECT odbc_time FROM %s WHERE odbc_time < {ts '2015-03-15 00:00:00.000'}",
TestsConstants.TEST_INDEX_ODBC));
JSONArray hits = getHits(response);
for (int i = 0; i < hits.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void init() throws Exception {
@Test
public void includeTest() throws IOException {
SearchHits response = query(String.format(
"SELECT include('*name','*ge'),include('b*'),include('*ddre*'),include('gender') FROM %s/account LIMIT 1000",
"SELECT include('*name','*ge'),include('b*'),include('*ddre*'),include('gender') FROM %s LIMIT 1000",
TEST_INDEX_ACCOUNT));
for (SearchHit hit : response.getHits()) {
Set<String> keySet = hit.getSourceAsMap().keySet();
Expand All @@ -48,7 +48,7 @@ public void includeTest() throws IOException {
public void excludeTest() throws IOException {

SearchHits response = query(String.format(
"SELECT exclude('*name','*ge'),exclude('b*'),exclude('*ddre*'),exclude('gender') FROM %s/account LIMIT 1000",
"SELECT exclude('*name','*ge'),exclude('b*'),exclude('*ddre*'),exclude('gender') FROM %s LIMIT 1000",
TEST_INDEX_ACCOUNT));

for (SearchHit hit : response.getHits()) {
Expand All @@ -65,7 +65,7 @@ public void excludeTest() throws IOException {
public void allTest() throws IOException {

SearchHits response = query(String.format(
"SELECT exclude('*name','*ge'),include('b*'),exclude('*ddre*'),include('gender') FROM %s/account LIMIT 1000",
"SELECT exclude('*name','*ge'),include('b*'),exclude('*ddre*'),include('gender') FROM %s LIMIT 1000",
TEST_INDEX_ACCOUNT));

for (SearchHit hit : response.getHits()) {
Expand Down
1 change: 0 additions & 1 deletion legacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,5 @@ dependencies {
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version:'2.2'
testImplementation group: 'org.mockito', name: 'mockito-inline', version:'3.12.4'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation group: "org.opensearch.client", name: 'transport', version: "${opensearch_version}"

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
public class From {
private String index;
private String type;
private String alias;

/**
Expand All @@ -23,22 +22,7 @@ public class From {
* @param from The part after the FROM keyword.
*/
public From(String from) {
if (from.startsWith("<")) {
index = from;
if (!from.endsWith(">")) {
int i = from.lastIndexOf('/');
if (-1 < i) {
index = from.substring(0, i);
type = from.substring(i + 1);
}
}
return;
}
String[] parts = from.split("/");
this.index = parts[0].trim();
if (parts.length == 2) {
this.type = parts[1].trim();
}
index = from;
}

public From(String from, String alias) {
Expand All @@ -54,14 +38,6 @@ public void setIndex(String index) {
this.index = index;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getAlias() {
return alias;
}
Expand All @@ -73,9 +49,6 @@ public void setAlias(String alias) {
@Override
public String toString() {
StringBuilder str = new StringBuilder(index);
if (type != null) {
str.append('/').append(type);
}
if (alias != null) {
str.append(" AS ").append(alias);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,4 @@ public String[] getIndexArr() {
}
return indexArr;
}

/**
* Get the types the query refer to.
*
* @return list of strings, the types names
*/
public String[] getTypeArr() {
List<String> list = new ArrayList<>();
From index = null;
for (int i = 0; i < from.size(); i++) {
index = from.get(i);
if (index.getType() != null && index.getType().trim().length() > 0) {
list.add(index.getType());
}
}
if (list.size() == 0) {
return null;
}

return list.toArray(new String[list.size()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public String path() {
*/
@SuppressWarnings("unchecked")
public String type() {
FieldMappingMetadata metaData = typeMappings.getOrDefault(fieldName, FieldMappingMetadata.NULL);
if (metaData.isNull()) {
FieldMappingMetadata metaData = typeMappings.get(fieldName);
if (metaData == null) {
dai-chen marked this conversation as resolved.
Show resolved Hide resolved
return DescribeResultSet.DEFAULT_OBJECT_DATATYPE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IndexMappings() {

public IndexMappings(Metadata metaData) {
this.indexMappings = buildMappings(metaData.indices(),
indexMetaData -> new FieldMappings(indexMetaData.getMappings().valuesIt().next()));
indexMetaData -> new FieldMappings(indexMetaData.mapping()));
}

public IndexMappings(ImmutableOpenMap<String, MappingMetadata> mappings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Schema buildSchema(List<ColumnNode> columnNodes) {
node.getAlias(),
node.getType()))
.collect(Collectors.toList());
return new Schema("dummy", "dummy", columnList);
return new Schema(columnList);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
public class Schema implements Iterable<Schema.Column> {

private String indexName;
private String typeName;
private List<Column> columns;

private static Set<String> types;
Expand All @@ -27,9 +26,8 @@ public class Schema implements Iterable<Schema.Column> {
types = getTypes();
}

public Schema(String indexName, String typeName, List<Column> columns) {
public Schema(String indexName, List<Column> columns) {
this.indexName = indexName;
this.typeName = typeName;
this.columns = columns;
}

Expand All @@ -46,10 +44,6 @@ public String getIndexName() {
return indexName;
}

public String getTypeName() {
return typeName;
}

public List<String> getHeaders() {
return columns.stream()
.map(column -> column.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class SelectResultSet extends ResultSet {

private boolean selectAll;
private String indexName;
private String typeName;
private List<Schema.Column> columns = new ArrayList<>();
private ColumnTypeProvider outputColumnType;

Expand Down Expand Up @@ -105,7 +104,7 @@ public SelectResultSet(Client client,
} else {
loadFromEsState(query);
}
this.schema = new Schema(indexName, typeName, columns);
this.schema = new Schema(indexName, columns);
this.head = schema.getHeaders();
this.dateFieldFormatter = new DateFieldFormatter(indexName, columns, fieldAliasMap);

Expand Down Expand Up @@ -142,7 +141,7 @@ public void populateResultSetFromCursor(Cursor cursor) {

private void populateResultSetFromDefaultCursor(DefaultCursor cursor) {
this.columns = cursor.getColumns();
this.schema = new Schema(null, null, columns);
this.schema = new Schema(columns);
this.head = schema.getHeaders();
this.dateFieldFormatter = new DateFieldFormatter(
cursor.getIndexPattern(),
Expand All @@ -163,50 +162,27 @@ private void populateResultSetFromDefaultCursor(DefaultCursor cursor) {
*/
private void loadFromEsState(Query query) {
String indexName = fetchIndexName(query);
String typeName = fetchTypeName(query);
String[] fieldNames = fetchFieldsAsArray(query);

// Reset boolean in the case of JOIN query where multiple calls to loadFromEsState() are made
selectAll = isSimpleQuerySelectAll(query) || isJoinQuerySelectAll(query, fieldNames);

GetFieldMappingsRequest request = new GetFieldMappingsRequest()
.indices(indexName)
.types(emptyArrayIfNull(typeName))
.fields(selectAllFieldsIfEmpty(fieldNames))
.local(true);
GetFieldMappingsResponse response = client.admin().indices()
.getFieldMappings(request)
.actionGet();

Map<String, Map<String, Map<String, FieldMappingMetadata>>> mappings = response.mappings();
if (mappings.isEmpty()) {
Map<String, Map<String, FieldMappingMetadata>> mappings = response.mappings();
if (mappings.isEmpty() || !mappings.containsKey(indexName)) {
throw new IllegalArgumentException(String.format("Index type %s does not exist", query.getFrom()));
}
Map<String, FieldMappingMetadata> typeMappings = mappings.get(indexName);

// Assumption is all indices share the same mapping which is validated in TermFieldRewriter.
Map<String, Map<String, FieldMappingMetadata>> indexMappings = mappings.values().iterator().next();

// if index mappings size is 0 and the expression is a cast: that means that we are casting by alias
// if so, add the original field that was being looked at to the mapping (how?)

/*
* There are three cases regarding type name to consider:
* 1. If the correct type name was given, its typeMapping is retrieved
* 2. If the incorrect type name was given then the response is null
* 3. If no type name is given, the indexMapping is searched for a typeMapping
*/
Map<String, FieldMappingMetadata> typeMappings = new HashMap<>();
if (indexMappings.containsKey(typeName)) {
typeMappings = indexMappings.get(typeName);
} else {
// Assuming OpenSearch version 6.x, there can be only one type per index so this for loop should grab the only type
for (String type : indexMappings.keySet()) {
typeMappings = indexMappings.get(type);
}
}

this.indexName = this.indexName == null ? indexName : (this.indexName + "|" + indexName);
this.typeName = this.typeName == null ? typeName : (this.typeName + "|" + typeName);
this.columns.addAll(renameColumnWithTableAlias(query, populateColumns(query, fieldNames, typeMappings)));
}

Expand Down Expand Up @@ -289,10 +265,6 @@ private String fetchIndexName(Query query) {
return query.getFrom().get(0).getIndex();
}

private String fetchTypeName(Query query) {
return query.getFrom().get(0).getType();
}

/**
* queryResult is checked to see if it's of type Aggregation in which case the aggregation fields in GROUP BY
* are returned as well. This prevents returning a Schema of all fields when SELECT * is called with
Expand Down
Loading