Skip to content

Commit 034027c

Browse files
authored
Merge pull request #1063 from penghuo/hp/main/2.4merge
Merge 2.x to main after 2.4 release
2 parents d28c17d + 7f377da commit 034027c

File tree

674 files changed

+467944
-9256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

674 files changed

+467944
-9256
lines changed

.github/workflows/sql-odbc-main.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ env:
1313
CI_OUTPUT_PATH: "sql-odbc/ci-output"
1414
ODBC_LIB_PATH: "./build/odbc/lib"
1515
ODBC_BIN_PATH: "./build/odbc/bin"
16-
ODBC_BUILD_PATH: "./build/odbc/build"
17-
AWS_SDK_INSTALL_PATH: "./build/aws-sdk/install"
16+
ODBC_BUILD_PATH: "./build/odbc/cmake"
17+
VCPKG_X64_INSTALL_PATH: ".\\src\\vcpkg_installed\\x64-windows"
18+
VCPKG_X86_INSTALL_PATH: ".\\src\\vcpkg_installed\\x86-windows"
1819

1920
# Tests are disabled (commented out) in all jobs because they are fail and/or outdated
2021
# Keeping them for the brighten future when we can re-activate them
2122
jobs:
2223
build-mac:
23-
runs-on: macos-10.15
24+
runs-on: macos-12
2425
defaults:
2526
run:
2627
working-directory: sql-odbc
@@ -103,7 +104,7 @@ jobs:
103104
- name: build-installer
104105
if: success()
105106
run: |
106-
.\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH
107+
.\scripts\build_installer.ps1 Release Win32 .\src $Env:ODBC_BUILD_PATH $Env:VCPKG_X86_INSTALL_PATH
107108
#- name: test
108109
# run: |
109110
# cp .\\libraries\\VisualLeakDetector\\bin32\\*.* .\\bin32\\Release
@@ -148,7 +149,7 @@ jobs:
148149
- name: build-installer
149150
if: success()
150151
run: |
151-
.\scripts\build_installer.ps1 Release x64 .\src $Env:ODBC_BUILD_PATH $Env:AWS_SDK_INSTALL_PATH
152+
.\scripts\build_installer.ps1 Release x64 .\src $Env:ODBC_BUILD_PATH $Env:VCPKG_X64_INSTALL_PATH
152153
#- name: test
153154
# run: |
154155
# cp .\\libraries\\VisualLeakDetector\\bin64\\*.* .\\bin64\\Release

.github/workflows/sql-test-and-build-workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
matrix:
2626
entry:
2727
- { os: ubuntu-latest, java: 11 }
28-
- { os: windows-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc}
28+
- { os: windows-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc -PbuildPlatform=windows }
2929
- { os: macos-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
3030
- { os: ubuntu-latest, java: 17 }
31-
- { os: windows-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
31+
- { os: windows-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc -PbuildPlatform=windows }
3232
- { os: macos-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc }
3333
runs-on: ${{ matrix.entry.os }}
3434

.github/workflows/sql-test-workflow.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ name: SQL Plugin Tests
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
name:
7+
required: false
8+
type: string
9+
10+
run-name:
11+
${{ inputs.name == '' && format('{0} @ {1}', github.ref_name, github.sha) || inputs.name }}
512

613
jobs:
714
build:
@@ -64,10 +71,10 @@ jobs:
6471
6572
- name: Verify test results
6673
run: |
67-
if [[ -e failures.log ]]
74+
if [[ -e report.log ]]
6875
then
6976
echo "## FAILED TESTS :facepalm::warning::bangbang:" >> $GITHUB_STEP_SUMMARY
70-
cat failures.log >> $GITHUB_STEP_SUMMARY
77+
cat report.log >> $GITHUB_STEP_SUMMARY
7178
exit 1
7279
fi
7380

.github/workflows/sql-workbench-test-and-build-workflow.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ jobs:
7777
with:
7878
name: workbench-${{ matrix.os }}
7979
path: ../OpenSearch-Dashboards/plugins/workbench/build
80-

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ gen
4242
.DS_Store
4343

4444
/artifacts/
45+
/.pid.lock
46+
/.prom.pid.lock
47+
48+
.java-version

DEVELOPER_GUIDE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ The plugin codebase is in standard layout of Gradle project::
141141
├── core
142142
├── doctest
143143
├── opensearch
144+
├── filesystem
145+
├── prometheus
144146
├── integ-test
145147
├── legacy
146148
├── plugin
@@ -159,6 +161,8 @@ Here are sub-folders (Gradle modules) for plugin source code:
159161
- ``ppl``: PPL language processor.
160162
- ``core``: core query engine.
161163
- ``opensearch``: OpenSearch storage engine.
164+
- ``prometheus``: Prometheus storage engine.
165+
- ``filesystem``: File System storage engine (in development).
162166
- ``protocol``: request/response protocol formatter.
163167
- ``common``: common util code.
164168
- ``integ-test``: integration and comparison test.

NOTICE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Foundation (http://www.apache.org/).
1111
This product includes software developed by
1212
Joda.org (http://www.joda.org/).
1313

14+
This product includes software developed by
15+
Kraken (https://github.com/thekrakken/java-grok).
16+
1417
This project is based on the Apache 2.0-licensed elasticsearch-sql project (https://github.com/NLPchina/elasticsearch-sql):
1518

1619
Copyright 2014 omershelef

build.gradle

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,46 @@ buildscript {
88
ext {
99
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
1010
spring_version = "5.3.22"
11-
jackson_version = "2.13.4"
11+
jackson_version = "2.14.1"
12+
jackson_databind_version = "2.14.1"
1213
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
1314
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
1415
version_tokens = opensearch_version.tokenize('-')
1516
opensearch_build = version_tokens[0] + '.0'
17+
prometheus_binary_version = "2.37.2"
1618
if (buildVersionQualifier) {
1719
opensearch_build += "-${buildVersionQualifier}"
1820
}
1921
if (isSnapshot) {
2022
// 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT (opensearch_build)
2123
opensearch_build += "-SNAPSHOT"
2224
}
25+
getArchType = {
26+
if (System.getProperty("os.arch").startsWith("x") || System.getProperty("os.arch").startsWith("amd")) {
27+
return "amd64"
28+
}
29+
else {
30+
return "arm64"
31+
}
32+
}
33+
getOSFamilyType = {
34+
def os = org.gradle.internal.os.OperatingSystem.current();
35+
if (os.isMacOsX()) {
36+
return "darwin"
37+
}
38+
else if(os.isLinux()){
39+
return "linux"
40+
}
41+
else if(os.isWindows()) {
42+
return "windows"
43+
}
44+
else {
45+
return os.getFamilyName().toString()
46+
}
47+
}
48+
getPrometheusBinaryLocation = { ->
49+
return "https://github.com/prometheus/prometheus/releases/download/v${prometheus_binary_version}/prometheus-${prometheus_binary_version}."+ getOSFamilyType() + "-" + getArchType() + ".tar.gz"
50+
}
2351
}
2452

2553
repositories {

common/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ dependencies {
3535
api "org.antlr:antlr4-runtime:4.7.1"
3636
api group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
3737
api group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.17.1'
38+
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
3839

3940
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
41+
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.9.1'
42+
testImplementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
43+
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
4044
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.common.grok;
7+
8+
import java.time.Instant;
9+
import java.time.LocalDate;
10+
import java.time.LocalDateTime;
11+
import java.time.OffsetDateTime;
12+
import java.time.ZoneId;
13+
import java.time.ZoneOffset;
14+
import java.time.ZonedDateTime;
15+
import java.time.format.DateTimeFormatter;
16+
import java.time.temporal.TemporalAccessor;
17+
import java.util.AbstractMap;
18+
import java.util.Arrays;
19+
import java.util.Collection;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.function.Function;
23+
import java.util.regex.Pattern;
24+
import java.util.stream.Collectors;
25+
26+
/**
27+
* Convert String argument to the right type.
28+
*/
29+
public class Converter {
30+
31+
public enum Type {
32+
BYTE(Byte::valueOf),
33+
BOOLEAN(Boolean::valueOf),
34+
SHORT(Short::valueOf),
35+
INT(Integer::valueOf, "integer"),
36+
LONG(Long::valueOf),
37+
FLOAT(Float::valueOf),
38+
DOUBLE(Double::valueOf),
39+
DATETIME(new DateConverter(), "date"),
40+
STRING(v -> v, "text");
41+
42+
public final IConverter<? extends Object> converter;
43+
public final List<String> aliases;
44+
45+
Type(IConverter<? extends Object> converter, String... aliases) {
46+
this.converter = converter;
47+
this.aliases = Arrays.asList(aliases);
48+
}
49+
}
50+
51+
private static final Pattern SPLITTER = Pattern.compile("[:;]");
52+
53+
private static final Map<String, Type> TYPES =
54+
Arrays.stream(Type.values())
55+
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
56+
57+
private static final Map<String, Type> TYPE_ALIASES =
58+
Arrays.stream(Type.values())
59+
.flatMap(type -> type.aliases.stream()
60+
.map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
61+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
62+
63+
private static Type getType(String key) {
64+
key = key.toLowerCase();
65+
Type type = TYPES.getOrDefault(key, TYPE_ALIASES.get(key));
66+
if (type == null) {
67+
throw new IllegalArgumentException("Invalid data type :" + key);
68+
}
69+
return type;
70+
}
71+
72+
/**
73+
* getConverters.
74+
*/
75+
public static Map<String, IConverter<? extends Object>>
76+
getConverters(Collection<String> groupNames, Object... params) {
77+
return groupNames.stream()
78+
.filter(Converter::containsDelimiter)
79+
.collect(Collectors.toMap(Function.identity(), key -> {
80+
String[] list = splitGrokPattern(key);
81+
IConverter<? extends Object> converter = getType(list[1]).converter;
82+
if (list.length == 3) {
83+
converter = converter.newConverter(list[2], params);
84+
}
85+
return converter;
86+
}));
87+
}
88+
89+
/**
90+
* getGroupTypes.
91+
*/
92+
public static Map<String, Type> getGroupTypes(Collection<String> groupNames) {
93+
return groupNames.stream()
94+
.filter(Converter::containsDelimiter)
95+
.map(Converter::splitGrokPattern)
96+
.collect(Collectors.toMap(
97+
l -> l[0],
98+
l -> getType(l[1])
99+
));
100+
}
101+
102+
public static String extractKey(String key) {
103+
return splitGrokPattern(key)[0];
104+
}
105+
106+
private static boolean containsDelimiter(String string) {
107+
return string.indexOf(':') >= 0 || string.indexOf(';') >= 0;
108+
}
109+
110+
private static String[] splitGrokPattern(String string) {
111+
return SPLITTER.split(string, 3);
112+
}
113+
114+
interface IConverter<T> {
115+
116+
T convert(String value);
117+
118+
default IConverter<T> newConverter(String param, Object... params) {
119+
return this;
120+
}
121+
}
122+
123+
124+
static class DateConverter implements IConverter<Instant> {
125+
126+
private final DateTimeFormatter formatter;
127+
private final ZoneId timeZone;
128+
129+
public DateConverter() {
130+
this.formatter = DateTimeFormatter.ISO_DATE_TIME;
131+
this.timeZone = ZoneOffset.UTC;
132+
}
133+
134+
private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) {
135+
this.formatter = formatter;
136+
this.timeZone = timeZone;
137+
}
138+
139+
@Override
140+
public Instant convert(String value) {
141+
TemporalAccessor dt = formatter
142+
.parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from,
143+
Instant::from,
144+
LocalDate::from);
145+
if (dt instanceof ZonedDateTime) {
146+
return ((ZonedDateTime) dt).toInstant();
147+
} else if (dt instanceof LocalDateTime) {
148+
return ((LocalDateTime) dt).atZone(timeZone).toInstant();
149+
} else if (dt instanceof OffsetDateTime) {
150+
return ((OffsetDateTime) dt).atZoneSameInstant(timeZone).toInstant();
151+
} else if (dt instanceof Instant) {
152+
return ((Instant) dt);
153+
} else if (dt instanceof LocalDate) {
154+
return ((LocalDate) dt).atStartOfDay(timeZone).toInstant();
155+
} else {
156+
return null;
157+
}
158+
}
159+
160+
@Override
161+
public DateConverter newConverter(String param, Object... params) {
162+
if (!(params.length == 1 && params[0] instanceof ZoneId)) {
163+
throw new IllegalArgumentException("Invalid parameters");
164+
}
165+
return new DateConverter(DateTimeFormatter.ofPattern(param), (ZoneId) params[0]);
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)