From 26913533250f7f99ecc7f9b644ca414e81133213 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Thu, 3 Aug 2023 13:28:23 -0700 Subject: [PATCH 1/4] Spotless apply for common directory. Signed-off-by: Mitchell Gale --- build.gradle | 3 +- .../antlr/CaseInsensitiveCharStream.java | 1 - .../antlr/SyntaxAnalysisErrorListener.java | 1 - .../common/antlr/SyntaxCheckException.java | 1 - .../AwsSigningInterceptor.java | 32 ++-- .../BasicAuthenticationInterceptor.java | 6 +- .../opensearch/sql/common/grok/Converter.java | 57 +++--- .../org/opensearch/sql/common/grok/Grok.java | 66 +++---- .../sql/common/grok/GrokCompiler.java | 62 +++---- .../opensearch/sql/common/grok/GrokUtils.java | 47 ++--- .../org/opensearch/sql/common/grok/Match.java | 143 +++++++------- .../common/grok/exception/GrokException.java | 12 +- .../sql/common/response/ResponseListener.java | 1 - .../sql/common/setting/LegacySettings.java | 24 +-- .../sql/common/setting/Settings.java | 24 +-- .../sql/common/utils/QueryContext.java | 26 ++- .../sql/common/utils/StringUtils.java | 43 ++--- .../AwsSigningInterceptorTest.java | 62 +++---- .../BasicAuthenticationInterceptorTest.java | 25 +-- .../sql/common/grok/ApacheDataTypeTest.java | 29 ++- .../sql/common/grok/ApacheTest.java | 2 - .../opensearch/sql/common/grok/BasicTest.java | 8 +- .../sql/common/grok/CaptureTest.java | 6 +- .../common/grok/GrokDocumentationTest.java | 44 +++-- .../opensearch/sql/common/grok/GrokTest.java | 175 ++++++++++-------- .../sql/common/grok/MessagesTest.java | 7 +- .../sql/common/grok/ResourceManager.java | 4 +- 27 files changed, 416 insertions(+), 495 deletions(-) diff --git a/build.gradle b/build.gradle index f623b5da4e..42a1e393e7 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,8 @@ spotless { java { target fileTree('.') { include 'datasources/**/*.java', - 'core/**/*.java' + 'core/**/*.java', + 'common/**/*.java' exclude '**/build/**', '**/build-*/**' } importOrder() diff --git a/common/src/main/java/org/opensearch/sql/common/antlr/CaseInsensitiveCharStream.java b/common/src/main/java/org/opensearch/sql/common/antlr/CaseInsensitiveCharStream.java index 0036da32a1..89381872ce 100644 --- a/common/src/main/java/org/opensearch/sql/common/antlr/CaseInsensitiveCharStream.java +++ b/common/src/main/java/org/opensearch/sql/common/antlr/CaseInsensitiveCharStream.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.antlr; import org.antlr.v4.runtime.CharStream; diff --git a/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java b/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java index b499a52967..76cbf52d58 100644 --- a/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java +++ b/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.antlr; import java.util.Locale; diff --git a/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxCheckException.java b/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxCheckException.java index 806cb7208b..d3c9c111ef 100644 --- a/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxCheckException.java +++ b/common/src/main/java/org/opensearch/sql/common/antlr/SyntaxCheckException.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.antlr; public class SyntaxCheckException extends RuntimeException { diff --git a/common/src/main/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptor.java b/common/src/main/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptor.java index 6c65c69c31..e2d33dca8b 100644 --- a/common/src/main/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptor.java +++ b/common/src/main/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptor.java @@ -31,15 +31,17 @@ public class AwsSigningInterceptor implements Interceptor { private static final Logger LOG = LogManager.getLogger(); /** - * AwsSigningInterceptor which intercepts http requests - * and adds required headers for sigv4 authentication. + * AwsSigningInterceptor which intercepts http requests and adds required headers for sigv4 + * authentication. * * @param awsCredentialsProvider awsCredentialsProvider. * @param region region. * @param serviceName serviceName. */ - public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvider, - @NonNull String region, @NonNull String serviceName) { + public AwsSigningInterceptor( + @NonNull AWSCredentialsProvider awsCredentialsProvider, + @NonNull String region, + @NonNull String serviceName) { this.okHttpAwsV4Signer = new OkHttpAwsV4Signer(region, serviceName); this.awsCredentialsProvider = awsCredentialsProvider; } @@ -48,25 +50,27 @@ public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvi public Response intercept(Interceptor.Chain chain) throws IOException { Request request = chain.request(); - DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'") - .withZone(ZoneId.of("GMT")); + DateTimeFormatter timestampFormat = + DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneId.of("GMT")); - - Request.Builder newRequestBuilder = request.newBuilder() - .addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now())) - .addHeader("host", request.url().host()); + Request.Builder newRequestBuilder = + request + .newBuilder() + .addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now())) + .addHeader("host", request.url().host()); AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials(); if (awsCredentialsProvider instanceof STSAssumeRoleSessionCredentialsProvider) { - newRequestBuilder.addHeader("x-amz-security-token", + newRequestBuilder.addHeader( + "x-amz-security-token", ((STSAssumeRoleSessionCredentialsProvider) awsCredentialsProvider) .getCredentials() .getSessionToken()); } Request newRequest = newRequestBuilder.build(); - Request signed = okHttpAwsV4Signer.sign(newRequest, - awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey()); + Request signed = + okHttpAwsV4Signer.sign( + newRequest, awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey()); return chain.proceed(signed); } - } diff --git a/common/src/main/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptor.java b/common/src/main/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptor.java index 34634d1580..2275482e30 100644 --- a/common/src/main/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptor.java +++ b/common/src/main/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptor.java @@ -22,13 +22,11 @@ public BasicAuthenticationInterceptor(@NonNull String username, @NonNull String this.credentials = Credentials.basic(username, password); } - @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request request = chain.request(); - Request authenticatedRequest = request.newBuilder() - .header("Authorization", credentials).build(); + Request authenticatedRequest = + request.newBuilder().header("Authorization", credentials).build(); return chain.proceed(authenticatedRequest); } - } diff --git a/common/src/main/java/org/opensearch/sql/common/grok/Converter.java b/common/src/main/java/org/opensearch/sql/common/grok/Converter.java index ebbe13f761..ddd3a2bbb4 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/Converter.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/Converter.java @@ -23,9 +23,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -/** - * Convert String argument to the right type. - */ +/** Convert String argument to the right type. */ public class Converter { public enum Type { @@ -51,13 +49,13 @@ public enum Type { private static final Pattern SPLITTER = Pattern.compile("[:;]"); private static final Map TYPES = - Arrays.stream(Type.values()) - .collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t)); + Arrays.stream(Type.values()).collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t)); private static final Map TYPE_ALIASES = Arrays.stream(Type.values()) - .flatMap(type -> type.aliases.stream() - .map(alias -> new AbstractMap.SimpleEntry<>(alias, type))) + .flatMap( + type -> + type.aliases.stream().map(alias -> new AbstractMap.SimpleEntry<>(alias, type))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); private static Type getType(String key) { @@ -69,34 +67,30 @@ private static Type getType(String key) { return type; } - /** - * getConverters. - */ - public static Map> - getConverters(Collection groupNames, Object... params) { + /** getConverters. */ + public static Map> getConverters( + Collection groupNames, Object... params) { return groupNames.stream() .filter(Converter::containsDelimiter) - .collect(Collectors.toMap(Function.identity(), key -> { - String[] list = splitGrokPattern(key); - IConverter converter = getType(list[1]).converter; - if (list.length == 3) { - converter = converter.newConverter(list[2], params); - } - return converter; - })); + .collect( + Collectors.toMap( + Function.identity(), + key -> { + String[] list = splitGrokPattern(key); + IConverter converter = getType(list[1]).converter; + if (list.length == 3) { + converter = converter.newConverter(list[2], params); + } + return converter; + })); } - /** - * getGroupTypes. - */ + /** getGroupTypes. */ public static Map getGroupTypes(Collection groupNames) { return groupNames.stream() .filter(Converter::containsDelimiter) .map(Converter::splitGrokPattern) - .collect(Collectors.toMap( - l -> l[0], - l -> getType(l[1]) - )); + .collect(Collectors.toMap(l -> l[0], l -> getType(l[1]))); } public static String extractKey(String key) { @@ -120,7 +114,6 @@ default IConverter newConverter(String param, Object... params) { } } - static class DateConverter implements IConverter { private final DateTimeFormatter formatter; @@ -138,8 +131,12 @@ private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) { @Override public Instant convert(String value) { - TemporalAccessor dt = formatter - .parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from, + TemporalAccessor dt = + formatter.parseBest( + value.trim(), + ZonedDateTime::from, + LocalDateTime::from, + OffsetDateTime::from, Instant::from, LocalDate::from); if (dt instanceof ZonedDateTime) { diff --git a/common/src/main/java/org/opensearch/sql/common/grok/Grok.java b/common/src/main/java/org/opensearch/sql/common/grok/Grok.java index f20f99cbc3..6dfab3f791 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/Grok.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/Grok.java @@ -16,36 +16,29 @@ import org.opensearch.sql.common.grok.Converter.IConverter; /** - * {@code Grok} parse arbitrary text and structure it. - *
- * {@code Grok} is simple API that allows you to easily parse logs - * and other files (single line). With {@code Grok}, - * you can turn unstructured log and event data into structured data. + * {@code Grok} parse arbitrary text and structure it.
+ * {@code Grok} is simple API that allows you to easily parse logs and other files (single line). + * With {@code Grok}, you can turn unstructured log and event data into structured data. * * @since 0.0.1 */ public class Grok implements Serializable { - /** - * Named regex of the originalGrokPattern. - */ + /** Named regex of the originalGrokPattern. */ private final String namedRegex; + /** - * Map of the named regex of the originalGrokPattern - * with id = namedregexid and value = namedregex. + * Map of the named regex of the originalGrokPattern with id = namedregexid and value = + * namedregex. */ private final Map namedRegexCollection; - /** - * Original {@code Grok} pattern (expl: %{IP}). - */ + + /** Original {@code Grok} pattern (expl: %{IP}). */ private final String originalGrokPattern; - /** - * Pattern of the namedRegex. - */ + + /** Pattern of the namedRegex. */ private final Pattern compiledNamedRegex; - /** - * {@code Grok} patterns definition. - */ + /** {@code Grok} patterns definition. */ private final Map grokPatternDefinition; public final Set namedGroups; @@ -54,19 +47,16 @@ public class Grok implements Serializable { public final Map> converters; - /** - * only use in grok discovery. - */ + /** only use in grok discovery. */ private String savedPattern = ""; - /** - * Grok. - */ - public Grok(String pattern, - String namedRegex, - Map namedRegexCollection, - Map patternDefinitions, - ZoneId defaultTimeZone) { + /** Grok. */ + public Grok( + String pattern, + String namedRegex, + Map namedRegexCollection, + Map patternDefinitions, + ZoneId defaultTimeZone) { this.originalGrokPattern = pattern; this.namedRegex = namedRegex; this.compiledNamedRegex = Pattern.compile(namedRegex); @@ -132,8 +122,8 @@ public Map getNamedRegexCollection() { } /** - * Match the given log with the named regex. - * And return the json representation of the matched element + * Match the given log with the named regex. And return the json representation of the + * matched element * * @param log : log to match * @return map containing matches @@ -144,8 +134,8 @@ public Map capture(String log) { } /** - * Match the given list of log with the named regex - * and return the list of json representation of the matched elements. + * Match the given list of log with the named regex and return the list of json + * representation of the matched elements. * * @param logs : list of log * @return list of maps containing matches @@ -159,8 +149,8 @@ public ArrayList> capture(List logs) { } /** - * Match the given text with the named regex - * {@code Grok} will extract data from the string and get an extence of {@link Match}. + * Match the given text with the named regex {@code Grok} will extract data from the + * string and get an extence of {@link Match}. * * @param text : Single line of log * @return Grok Match @@ -172,9 +162,7 @@ public Match match(CharSequence text) { Matcher matcher = compiledNamedRegex.matcher(text); if (matcher.find()) { - return new Match( - text, this, matcher, matcher.start(0), matcher.end(0) - ); + return new Match(text, this, matcher, matcher.start(0), matcher.end(0)); } return Match.EMPTY; diff --git a/common/src/main/java/org/opensearch/sql/common/grok/GrokCompiler.java b/common/src/main/java/org/opensearch/sql/common/grok/GrokCompiler.java index 18894fc7a1..aba96ad4cb 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/GrokCompiler.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/GrokCompiler.java @@ -31,13 +31,10 @@ public class GrokCompiler implements Serializable { // We don't want \n and commented line private static final Pattern patternLinePattern = Pattern.compile("^([A-z0-9_]+)\\s+(.*)$"); - /** - * {@code Grok} patterns definitions. - */ + /** {@code Grok} patterns definitions. */ private final Map grokPatternDefinitions = new HashMap<>(); - private GrokCompiler() { - } + private GrokCompiler() {} public static GrokCompiler newInstance() { return new GrokCompiler(); @@ -50,10 +47,10 @@ public Map getPatternDefinitions() { /** * Registers a new pattern definition. * - * @param name : Pattern Name + * @param name : Pattern Name * @param pattern : Regular expression Or {@code Grok} pattern * @throws GrokException runtime expt - **/ + */ public void register(String name, String pattern) { name = Objects.requireNonNull(name).trim(); pattern = Objects.requireNonNull(pattern).trim(); @@ -63,9 +60,7 @@ public void register(String name, String pattern) { } } - /** - * Registers multiple pattern definitions. - */ + /** Registers multiple pattern definitions. */ public void register(Map patternDefinitions) { Objects.requireNonNull(patternDefinitions); patternDefinitions.forEach(this::register); @@ -78,12 +73,9 @@ public void register(InputStream input) throws IOException { register(input, StandardCharsets.UTF_8); } - /** - * Registers multiple pattern definitions from a given inputStream. - */ + /** Registers multiple pattern definitions from a given inputStream. */ public void register(InputStream input, Charset charset) throws IOException { - try ( - BufferedReader in = new BufferedReader(new InputStreamReader(input, charset))) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(input, charset))) { in.lines() .map(patternLinePattern::matcher) .filter(Matcher::matches) @@ -91,11 +83,10 @@ public void register(InputStream input, Charset charset) throws IOException { } } - /** - * Registers multiple pattern definitions from a given Reader. - */ + /** Registers multiple pattern definitions from a given Reader. */ public void register(Reader input) throws IOException { - new BufferedReader(input).lines() + new BufferedReader(input) + .lines() .map(patternLinePattern::matcher) .filter(Matcher::matches) .forEach(m -> register(m.group(1), m.group(2))); @@ -109,9 +100,7 @@ public void registerPatternFromClasspath(String path) throws GrokException { registerPatternFromClasspath(path, StandardCharsets.UTF_8); } - /** - * registerPatternFromClasspath. - */ + /** registerPatternFromClasspath. */ public void registerPatternFromClasspath(String path, Charset charset) throws GrokException { final InputStream inputStream = this.getClass().getResourceAsStream(path); try (Reader reader = new InputStreamReader(inputStream, charset)) { @@ -121,9 +110,7 @@ public void registerPatternFromClasspath(String path, Charset charset) throws Gr } } - /** - * Compiles a given Grok pattern and returns a Grok object which can parse the pattern. - */ + /** Compiles a given Grok pattern and returns a Grok object which can parse the pattern. */ public Grok compile(String pattern) throws IllegalArgumentException { return compile(pattern, false); } @@ -135,11 +122,11 @@ public Grok compile(final String pattern, boolean namedOnly) throws IllegalArgum /** * Compiles a given Grok pattern and returns a Grok object which can parse the pattern. * - * @param pattern : Grok pattern (ex: %{IP}) - * @param defaultTimeZone : time zone used to parse a timestamp when it doesn't contain - * the time zone - * @param namedOnly : Whether to capture named expressions only or not (i.e. %{IP:ip} - * but not ${IP}) + * @param pattern : Grok pattern (ex: %{IP}) + * @param defaultTimeZone : time zone used to parse a timestamp when it doesn't contain the time + * zone + * @param namedOnly : Whether to capture named expressions only or not (i.e. %{IP:ip} but not + * ${IP}) * @return a compiled pattern * @throws IllegalArgumentException when pattern definition is invalid */ @@ -184,14 +171,15 @@ public Grok compile(final String pattern, ZoneId defaultTimeZone, boolean namedO for (int i = 0; i < count; i++) { String definitionOfPattern = patternDefinitions.get(group.get("pattern")); if (definitionOfPattern == null) { - throw new IllegalArgumentException(format("No definition for key '%s' found, aborting", - group.get("pattern"))); + throw new IllegalArgumentException( + format("No definition for key '%s' found, aborting", group.get("pattern"))); } String replacement = String.format("(?%s)", index, definitionOfPattern); if (namedOnly && group.get("subname") == null) { replacement = String.format("(?:%s)", definitionOfPattern); } - namedRegexCollection.put("name" + index, + namedRegexCollection.put( + "name" + index, (group.get("subname") != null ? group.get("subname") : group.get("name"))); namedRegex = StringUtils.replace(namedRegex, "%{" + group.get("name") + "}", replacement, 1); @@ -205,12 +193,6 @@ public Grok compile(final String pattern, ZoneId defaultTimeZone, boolean namedO throw new IllegalArgumentException("Pattern not found"); } - return new Grok( - pattern, - namedRegex, - namedRegexCollection, - patternDefinitions, - defaultTimeZone - ); + return new Grok(pattern, namedRegex, namedRegexCollection, patternDefinitions, defaultTimeZone); } } diff --git a/common/src/main/java/org/opensearch/sql/common/grok/GrokUtils.java b/common/src/main/java/org/opensearch/sql/common/grok/GrokUtils.java index 9ff65acde2..4b145bbbe8 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/GrokUtils.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/GrokUtils.java @@ -12,7 +12,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; - /** * {@code GrokUtils} contain set of useful tools or methods. * @@ -20,29 +19,25 @@ */ public class GrokUtils { - /** - * Extract Grok patter like %{FOO} to FOO, Also Grok pattern with semantic. - */ - public static final Pattern GROK_PATTERN = Pattern.compile( - "%\\{" - + "(?" - + "(?[A-z0-9]+)" - + "(?::(?[A-z0-9_:;,\\-\\/\\s\\.']+))?" - + ")" - + "(?:=(?" - + "(?:" - + "(?:[^{}]+|\\.+)+" - + ")+" - + ")" - + ")?" - + "\\}"); - - public static final Pattern NAMED_REGEX = Pattern - .compile("\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>"); - - /** - * getNameGroups. - */ + /** Extract Grok patter like %{FOO} to FOO, Also Grok pattern with semantic. */ + public static final Pattern GROK_PATTERN = + Pattern.compile( + "%\\{" + + "(?" + + "(?[A-z0-9]+)" + + "(?::(?[A-z0-9_:;,\\-\\/\\s\\.']+))?" + + ")" + + "(?:=(?" + + "(?:" + + "(?:[^{}]+|\\.+)+" + + ")+" + + ")" + + ")?" + + "\\}"); + + public static final Pattern NAMED_REGEX = Pattern.compile("\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>"); + + /** getNameGroups. */ public static Set getNameGroups(String regex) { Set namedGroups = new LinkedHashSet<>(); Matcher matcher = NAMED_REGEX.matcher(regex); @@ -52,9 +47,7 @@ public static Set getNameGroups(String regex) { return namedGroups; } - /** - * namedGroups. - */ + /** namedGroups. */ public static Map namedGroups(Matcher matcher, Set groupNames) { Map namedGroups = new LinkedHashMap<>(); for (String groupName : groupNames) { diff --git a/common/src/main/java/org/opensearch/sql/common/grok/Match.java b/common/src/main/java/org/opensearch/sql/common/grok/Match.java index 6831f35cee..3771817bba 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/Match.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/Match.java @@ -5,7 +5,6 @@ package org.opensearch.sql.common.grok; - import static java.lang.String.format; import java.util.ArrayList; @@ -31,9 +30,7 @@ public class Match { private boolean keepEmptyCaptures = true; private Map capture = Collections.emptyMap(); - /** - * Create a new {@code Match} object. - */ + /** Create a new {@code Match} object. */ public Match(CharSequence subject, Grok grok, Matcher match, int start, int end) { this.subject = subject; this.grok = grok; @@ -42,9 +39,7 @@ public Match(CharSequence subject, Grok grok, Matcher match, int start, int end) this.end = end; } - /** - * Create Empty grok matcher. - */ + /** Create Empty grok matcher. */ public static final Match EMPTY = new Match("", null, null, 0, 0); public Matcher getMatch() { @@ -59,9 +54,7 @@ public int getEnd() { return end; } - /** - * Ignore empty captures. - */ + /** Ignore empty captures. */ public void setKeepEmptyCaptures(boolean ignore) { // clear any cached captures if (capture.size() > 0) { @@ -97,8 +90,8 @@ public Map capture() { * * @param flattened will it flatten values. * @return the matched elements. - * @throws GrokException if a keys has multiple non-null values, but only if flattened is set - * to true. + * @throws GrokException if a keys has multiple non-null values, but only if flattened is set to + * true. */ private Map capture(boolean flattened) throws GrokException { if (match == null) { @@ -116,70 +109,69 @@ private Map capture(boolean flattened) throws GrokException { Map mappedw = GrokUtils.namedGroups(this.match, this.grok.namedGroups); - mappedw.forEach((key, valueString) -> { - String id = this.grok.getNamedRegexCollectionById(key); - if (id != null && !id.isEmpty()) { - key = id; - } - - if ("UNWANTED".equals(key)) { - return; - } - - Object value = valueString; - if (valueString != null) { - IConverter converter = grok.converters.get(key); - - if (converter != null) { - key = Converter.extractKey(key); - try { - value = converter.convert(valueString); - } catch (Exception e) { - capture.put(key + "_grokfailure", e.toString()); + mappedw.forEach( + (key, valueString) -> { + String id = this.grok.getNamedRegexCollectionById(key); + if (id != null && !id.isEmpty()) { + key = id; } - if (value instanceof String) { - value = cleanString((String) value); + if ("UNWANTED".equals(key)) { + return; } - } else { - value = cleanString(valueString); - } - } else if (!isKeepEmptyCaptures()) { - return; - } - - if (capture.containsKey(key)) { - Object currentValue = capture.get(key); - if (flattened) { - if (currentValue == null && value != null) { - capture.put(key, value); - } - if (currentValue != null && value != null) { - throw new GrokException( - format( - "key '%s' has multiple non-null values, this is not allowed in flattened mode," - + " values:'%s', '%s'", - key, - currentValue, - value)); + Object value = valueString; + if (valueString != null) { + IConverter converter = grok.converters.get(key); + + if (converter != null) { + key = Converter.extractKey(key); + try { + value = converter.convert(valueString); + } catch (Exception e) { + capture.put(key + "_grokfailure", e.toString()); + } + + if (value instanceof String) { + value = cleanString((String) value); + } + } else { + value = cleanString(valueString); + } + } else if (!isKeepEmptyCaptures()) { + return; } - } else { - if (currentValue instanceof List) { - @SuppressWarnings("unchecked") - List cvl = (List) currentValue; - cvl.add(value); + + if (capture.containsKey(key)) { + Object currentValue = capture.get(key); + + if (flattened) { + if (currentValue == null && value != null) { + capture.put(key, value); + } + if (currentValue != null && value != null) { + throw new GrokException( + format( + "key '%s' has multiple non-null values, this is not allowed in flattened" + + " mode, values:'%s', '%s'", + key, currentValue, value)); + } + } else { + if (currentValue instanceof List) { + @SuppressWarnings("unchecked") + List cvl = (List) currentValue; + cvl.add(value); + } else { + List list = new ArrayList(); + list.add(currentValue); + list.add(value); + capture.put(key, list); + } + } } else { - List list = new ArrayList(); - list.add(currentValue); - list.add(value); - capture.put(key, list); + capture.put(key, value); } - } - } else { - capture.put(key, value); - } - }); + }); capture = Collections.unmodifiableMap(capture); @@ -189,13 +181,11 @@ private Map capture(boolean flattened) throws GrokException { /** * Match to the subject the regex and save the matched element into a map * - *

Multiple values to the same key are flattened to one value: the sole non-null value will - * be captured. - * Should there be multiple non-null values a RuntimeException is being thrown. + *

Multiple values to the same key are flattened to one value: the sole non-null value will be + * captured. Should there be multiple non-null values a RuntimeException is being thrown. * *

This can be used in cases like: (foo (.*:message) bar|bar (.*:message) foo) where the regexp - * guarantees that only - * one value will be captured. + * guarantees that only one value will be captured. * *

See also {@link #capture} which returns multiple values of the same key as list. * @@ -220,9 +210,7 @@ private String cleanString(String value) { char firstChar = value.charAt(0); char lastChar = value.charAt(value.length() - 1); - if (firstChar == lastChar - && (firstChar == '"' || firstChar == '\'') - ) { + if (firstChar == lastChar && (firstChar == '"' || firstChar == '\'')) { if (value.length() <= 2) { return ""; } else { @@ -249,5 +237,4 @@ private String cleanString(String value) { public Boolean isNull() { return this.match == null; } - } diff --git a/common/src/main/java/org/opensearch/sql/common/grok/exception/GrokException.java b/common/src/main/java/org/opensearch/sql/common/grok/exception/GrokException.java index 54ca8aada3..0e9d6d2ddf 100644 --- a/common/src/main/java/org/opensearch/sql/common/grok/exception/GrokException.java +++ b/common/src/main/java/org/opensearch/sql/common/grok/exception/GrokException.java @@ -6,9 +6,8 @@ package org.opensearch.sql.common.grok.exception; /** - * Signals that an {@code Grok} exception of some sort has occurred. - * This class is the general class of - * exceptions produced by failed or interrupted Grok operations. + * Signals that an {@code Grok} exception of some sort has occurred. This class is the general class + * of exceptions produced by failed or interrupted Grok operations. * * @since 0.0.4 */ @@ -16,9 +15,7 @@ public class GrokException extends RuntimeException { private static final long serialVersionUID = 1L; - /** - * Creates a new GrokException. - */ + /** Creates a new GrokException. */ public GrokException() { super(); } @@ -27,7 +24,7 @@ public GrokException() { * Constructs a new GrokException. * * @param message the reason for the exception - * @param cause the underlying Throwable that caused this exception to be thrown. + * @param cause the underlying Throwable that caused this exception to be thrown. */ public GrokException(String message, Throwable cause) { super(message, cause); @@ -50,5 +47,4 @@ public GrokException(String message) { public GrokException(Throwable cause) { super(cause); } - } diff --git a/common/src/main/java/org/opensearch/sql/common/response/ResponseListener.java b/common/src/main/java/org/opensearch/sql/common/response/ResponseListener.java index 3d5eadc692..bac79ddbbd 100644 --- a/common/src/main/java/org/opensearch/sql/common/response/ResponseListener.java +++ b/common/src/main/java/org/opensearch/sql/common/response/ResponseListener.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.response; /** diff --git a/common/src/main/java/org/opensearch/sql/common/setting/LegacySettings.java b/common/src/main/java/org/opensearch/sql/common/setting/LegacySettings.java index 172a0d8023..e8dc76645a 100644 --- a/common/src/main/java/org/opensearch/sql/common/setting/LegacySettings.java +++ b/common/src/main/java/org/opensearch/sql/common/setting/LegacySettings.java @@ -3,42 +3,31 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.setting; import lombok.Getter; import lombok.RequiredArgsConstructor; -/** - * Legacy Open Distro Settings. - */ +/** Legacy Open Distro Settings. */ public abstract class LegacySettings { @RequiredArgsConstructor public enum Key { - /** - * Legacy SQL Settings. - */ + /** Legacy SQL Settings. */ SQL_ENABLED("opendistro.sql.enabled"), SQL_QUERY_SLOWLOG("opendistro.sql.query.slowlog"), SQL_CURSOR_KEEPALIVE("opendistro.sql.cursor.keep_alive"), METRICS_ROLLING_WINDOW("opendistro.sql.metrics.rollingwindow"), METRICS_ROLLING_INTERVAL("opendistro.sql.metrics.rollinginterval"), - /** - * Legacy PPL Settings. - */ + /** Legacy PPL Settings. */ PPL_ENABLED("opendistro.ppl.enabled"), PPL_QUERY_MEMORY_LIMIT("opendistro.ppl.query.memory_limit"), - /** - * Legacy Common Settings. - */ + /** Legacy Common Settings. */ QUERY_SIZE_LIMIT("opendistro.query.size_limit"), - /** - * Deprecated Settings. - */ + /** Deprecated Settings. */ SQL_NEW_ENGINE_ENABLED("opendistro.sql.engine.new.enabled"), QUERY_ANALYSIS_ENABLED("opendistro.sql.query.analysis.enabled"), QUERY_ANALYSIS_SEMANTIC_SUGGESTION("opendistro.sql.query.analysis.semantic.suggestion"), @@ -47,8 +36,7 @@ public enum Key { SQL_CURSOR_ENABLED("opendistro.sql.cursor.enabled"), SQL_CURSOR_FETCH_SIZE("opendistro.sql.cursor.fetch_size"); - @Getter - private final String keyValue; + @Getter private final String keyValue; } public abstract T getSettingValue(Key key); diff --git a/common/src/main/java/org/opensearch/sql/common/setting/Settings.java b/common/src/main/java/org/opensearch/sql/common/setting/Settings.java index 3b0eba157d..1e5243f91f 100644 --- a/common/src/main/java/org/opensearch/sql/common/setting/Settings.java +++ b/common/src/main/java/org/opensearch/sql/common/setting/Settings.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.setting; import com.google.common.base.Strings; @@ -14,29 +13,21 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -/** - * Setting. - */ +/** Setting. */ public abstract class Settings { @RequiredArgsConstructor public enum Key { - /** - * SQL Settings. - */ + /** SQL Settings. */ SQL_ENABLED("plugins.sql.enabled"), SQL_SLOWLOG("plugins.sql.slowlog"), SQL_CURSOR_KEEP_ALIVE("plugins.sql.cursor.keep_alive"), SQL_DELETE_ENABLED("plugins.sql.delete.enabled"), - /** - * PPL Settings. - */ + /** PPL Settings. */ PPL_ENABLED("plugins.ppl.enabled"), - /** - * Common Settings for SQL and PPL. - */ + /** Common Settings for SQL and PPL. */ QUERY_MEMORY_LIMIT("plugins.query.memory_limit"), QUERY_SIZE_LIMIT("plugins.query.size_limit"), ENCYRPTION_MASTER_KEY("plugins.query.datasources.encryption.masterkey"), @@ -47,8 +38,7 @@ public enum Key { CLUSTER_NAME("cluster.name"); - @Getter - private final String keyValue; + @Getter private final String keyValue; private static final Map ALL_KEYS; @@ -66,9 +56,7 @@ public static Optional of(String keyValue) { } } - /** - * Get Setting Value. - */ + /** Get Setting Value. */ public abstract T getSettingValue(Key key); public abstract List getSettings(); diff --git a/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java b/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java index 19c3d9588c..686263238a 100644 --- a/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java +++ b/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.utils; import java.util.Map; @@ -11,25 +10,23 @@ import org.apache.logging.log4j.ThreadContext; /** - * Utility class for recording and accessing context for the query being executed. - * Implementation Details: context variables is being persisted statically in the thread context + * Utility class for recording and accessing context for the query being executed. Implementation + * Details: context variables is being persisted statically in the thread context + * * @see: @ThreadContext */ public class QueryContext { - /** - * The key of the request id in the context map. - */ + /** The key of the request id in the context map. */ private static final String REQUEST_ID_KEY = "request_id"; /** * Generates a random UUID and adds to the {@link ThreadContext} as the request id. - *

- * Note: If a request id already present, this method will overwrite it with a new - * one. This is to pre-vent re-using the same request id for different requests in - * case the same thread handles both of them. But this also means one should not - * call this method twice on the same thread within the lifetime of the request. - *

+ * + *

Note: If a request id already present, this method will overwrite it with a new one. This is + * to pre-vent re-using the same request id for different requests in case the same thread handles + * both of them. But this also means one should not call this method twice on the same thread + * within the lifetime of the request. */ public static String addRequestId() { var id = UUID.randomUUID().toString(); @@ -39,6 +36,7 @@ public static String addRequestId() { /** * Get RequestID. + * * @return the current request id from {@link ThreadContext}. */ public static String getRequestId() { @@ -50,8 +48,8 @@ public static String getRequestId() { } /** - * Wraps a given instance of {@link Runnable} into a new one which gets all the - * entries from current ThreadContext map. + * Wraps a given instance of {@link Runnable} into a new one which gets all the entries from + * current ThreadContext map. * * @param task the instance of Runnable to wrap * @return the new task diff --git a/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java b/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java index bd3a5a9779..87b0ad3c29 100644 --- a/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java +++ b/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.common.utils; import com.google.common.base.Strings; @@ -12,15 +11,14 @@ public class StringUtils { /** - * Unquote Identifier which has " or ' as mark. - * Strings quoted by ' or " with two of these quotes appearing next to each other in the quote - * acts as an escape - * Example: 'Test''s' will result in 'Test's', similar with those single quotes being replaced - * with double quote. - * Supports escaping quotes (single/double) and escape characters using the `\` characters. + * Unquote Identifier which has " or ' as mark. Strings quoted by ' or " with two of these quotes + * appearing next to each other in the quote acts as an escape
+ * Example: 'Test''s' will result in + * 'Test's', similar with those single quotes being replaced with double quote. Supports escaping + * quotes (single/double) and escape characters using the `\` characters. + * * @param text string - * @return An unquoted string whose outer pair of (single/double) quotes have been - * removed + * @return An unquoted string whose outer pair of (single/double) quotes have been removed */ public static String unquoteText(String text) { if (text.length() < 2) { @@ -39,9 +37,7 @@ public static String unquoteText(String text) { return text.substring(1, text.length() - 1); } - if (firstChar == lastChar - && (firstChar == '\'' - || firstChar == '"')) { + if (firstChar == lastChar && (firstChar == '\'' || firstChar == '"')) { enclosingQuote = firstChar; } else { return text; @@ -57,12 +53,8 @@ public static String unquoteText(String text) { currentChar = text.charAt(chIndex); nextChar = text.charAt(chIndex + 1); - if ((currentChar == '\\' - && (nextChar == '"' - || nextChar == '\\' - || nextChar == '\'')) - || (currentChar == nextChar - && currentChar == enclosingQuote)) { + if ((currentChar == '\\' && (nextChar == '"' || nextChar == '\\' || nextChar == '\'')) + || (currentChar == nextChar && currentChar == enclosingQuote)) { chIndex++; currentChar = nextChar; } @@ -73,9 +65,9 @@ public static String unquoteText(String text) { /** * Unquote Identifier which has ` as mark. + * * @param identifier identifier that possibly enclosed by double quotes or back ticks - * @return An unquoted string whose outer pair of (double/back-tick) quotes have been - * removed + * @return An unquoted string whose outer pair of (double/back-tick) quotes have been removed */ public static String unquoteIdentifier(String identifier) { if (isQuoted(identifier, "`")) { @@ -86,16 +78,15 @@ public static String unquoteIdentifier(String identifier) { } /** - * Returns a formatted string using the specified format string and - * arguments, as well as the {@link Locale#ROOT} locale. + * Returns a formatted string using the specified format string and arguments, as well as the + * {@link Locale#ROOT} locale. * * @param format format string - * @param args arguments referenced by the format specifiers in the format string + * @param args arguments referenced by the format specifiers in the format string * @return A formatted string * @throws IllegalFormatException If a format string contains an illegal syntax, a format - * specifier that is incompatible with the given arguments, - * insufficient arguments given the format string, or other - * illegal conditions. + * specifier that is incompatible with the given arguments, insufficient arguments given the + * format string, or other illegal conditions. * @see java.lang.String#format(Locale, String, Object...) */ public static String format(final String format, Object... args) { diff --git a/common/src/test/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptorTest.java b/common/src/test/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptorTest.java index 21a8bbf6e7..435ac9dc93 100644 --- a/common/src/test/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptorTest.java +++ b/common/src/test/java/org/opensearch/sql/common/authinterceptors/AwsSigningInterceptorTest.java @@ -7,7 +7,6 @@ package org.opensearch.sql.common.authinterceptors; - import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.AWSSessionCredentials; import com.amazonaws.auth.AWSStaticCredentialsProvider; @@ -28,37 +27,36 @@ @ExtendWith(MockitoExtension.class) public class AwsSigningInterceptorTest { - @Mock - private Interceptor.Chain chain; + @Mock private Interceptor.Chain chain; - @Captor - ArgumentCaptor requestArgumentCaptor; + @Captor ArgumentCaptor requestArgumentCaptor; - @Mock - private STSAssumeRoleSessionCredentialsProvider stsAssumeRoleSessionCredentialsProvider; + @Mock private STSAssumeRoleSessionCredentialsProvider stsAssumeRoleSessionCredentialsProvider; @Test void testConstructors() { - Assertions.assertThrows(NullPointerException.class, () -> - new AwsSigningInterceptor(null, "us-east-1", "aps")); - Assertions.assertThrows(NullPointerException.class, () -> - new AwsSigningInterceptor(getStaticAWSCredentialsProvider("accessKey", "secretKey"), null, - "aps")); - Assertions.assertThrows(NullPointerException.class, () -> - new AwsSigningInterceptor(getStaticAWSCredentialsProvider("accessKey", "secretKey"), - "us-east-1", null)); + Assertions.assertThrows( + NullPointerException.class, () -> new AwsSigningInterceptor(null, "us-east-1", "aps")); + Assertions.assertThrows( + NullPointerException.class, + () -> + new AwsSigningInterceptor( + getStaticAWSCredentialsProvider("accessKey", "secretKey"), null, "aps")); + Assertions.assertThrows( + NullPointerException.class, + () -> + new AwsSigningInterceptor( + getStaticAWSCredentialsProvider("accessKey", "secretKey"), "us-east-1", null)); } @Test @SneakyThrows void testIntercept() { - Mockito.when(chain.request()).thenReturn(new Request.Builder() - .url("http://localhost:9090") - .build()); - AwsSigningInterceptor awsSigningInterceptor - = new AwsSigningInterceptor( - getStaticAWSCredentialsProvider("testAccessKey", "testSecretKey"), - "us-east-1", "aps"); + Mockito.when(chain.request()) + .thenReturn(new Request.Builder().url("http://localhost:9090").build()); + AwsSigningInterceptor awsSigningInterceptor = + new AwsSigningInterceptor( + getStaticAWSCredentialsProvider("testAccessKey", "testSecretKey"), "us-east-1", "aps"); awsSigningInterceptor.intercept(chain); Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); @@ -67,31 +65,26 @@ void testIntercept() { Assertions.assertNotNull(request.headers("host")); } - @Test @SneakyThrows void testSTSCredentialsProviderInterceptor() { - Mockito.when(chain.request()).thenReturn(new Request.Builder() - .url("http://localhost:9090") - .build()); + Mockito.when(chain.request()) + .thenReturn(new Request.Builder().url("http://localhost:9090").build()); Mockito.when(stsAssumeRoleSessionCredentialsProvider.getCredentials()) .thenReturn(getAWSSessionCredentials()); - AwsSigningInterceptor awsSigningInterceptor - = new AwsSigningInterceptor(stsAssumeRoleSessionCredentialsProvider, - "us-east-1", "aps"); + AwsSigningInterceptor awsSigningInterceptor = + new AwsSigningInterceptor(stsAssumeRoleSessionCredentialsProvider, "us-east-1", "aps"); awsSigningInterceptor.intercept(chain); Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); Assertions.assertNotNull(request.headers("Authorization")); Assertions.assertNotNull(request.headers("x-amz-date")); Assertions.assertNotNull(request.headers("host")); - Assertions.assertEquals("session_token", - request.headers("x-amz-security-token").get(0)); + Assertions.assertEquals("session_token", request.headers("x-amz-security-token").get(0)); } - - private AWSCredentialsProvider getStaticAWSCredentialsProvider(String accessKey, - String secretKey) { + private AWSCredentialsProvider getStaticAWSCredentialsProvider( + String accessKey, String secretKey) { return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } @@ -113,5 +106,4 @@ public String getAWSSecretKey() { } }; } - } diff --git a/common/src/test/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptorTest.java b/common/src/test/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptorTest.java index 596894da6d..d59928d2ef 100644 --- a/common/src/test/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptorTest.java +++ b/common/src/test/java/org/opensearch/sql/common/authinterceptors/BasicAuthenticationInterceptorTest.java @@ -24,29 +24,25 @@ @ExtendWith(MockitoExtension.class) public class BasicAuthenticationInterceptorTest { - @Mock - private Interceptor.Chain chain; + @Mock private Interceptor.Chain chain; - @Captor - ArgumentCaptor requestArgumentCaptor; + @Captor ArgumentCaptor requestArgumentCaptor; @Test void testConstructors() { - Assertions.assertThrows(NullPointerException.class, () -> - new BasicAuthenticationInterceptor(null, "test")); - Assertions.assertThrows(NullPointerException.class, () -> - new BasicAuthenticationInterceptor("testAdmin", null)); + Assertions.assertThrows( + NullPointerException.class, () -> new BasicAuthenticationInterceptor(null, "test")); + Assertions.assertThrows( + NullPointerException.class, () -> new BasicAuthenticationInterceptor("testAdmin", null)); } - @Test @SneakyThrows void testIntercept() { - Mockito.when(chain.request()).thenReturn(new Request.Builder() - .url("http://localhost:9090") - .build()); - BasicAuthenticationInterceptor basicAuthenticationInterceptor - = new BasicAuthenticationInterceptor("testAdmin", "testPassword"); + Mockito.when(chain.request()) + .thenReturn(new Request.Builder().url("http://localhost:9090").build()); + BasicAuthenticationInterceptor basicAuthenticationInterceptor = + new BasicAuthenticationInterceptor("testAdmin", "testPassword"); basicAuthenticationInterceptor.intercept(chain); Mockito.verify(chain).proceed(requestArgumentCaptor.capture()); Request request = requestArgumentCaptor.getValue(); @@ -54,5 +50,4 @@ void testIntercept() { Collections.singletonList(Credentials.basic("testAdmin", "testPassword")), request.headers("Authorization")); } - } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/ApacheDataTypeTest.java b/common/src/test/java/org/opensearch/sql/common/grok/ApacheDataTypeTest.java index 09695c8220..7eb0e964de 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/ApacheDataTypeTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/ApacheDataTypeTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.common.grok; - import static org.junit.Assert.assertEquals; import com.google.common.io.Resources; @@ -42,12 +41,13 @@ public void setup() throws Exception { @Test public void test002_httpd_access_semi() throws GrokException { - Grok grok = compiler.compile( - "%{IPORHOST:clientip} %{USER:ident;boolean} %{USER:auth} " - + "\\[%{HTTPDATE:timestamp;date;dd/MMM/yyyy:HH:mm:ss Z}\\] \"(?:%{WORD:verb;string} " - + "%{NOTSPACE:request}" - + "(?: HTTP/%{NUMBER:httpversion;float})?|%{DATA:rawrequest})\" %{NUMBER:response;int} " - + "(?:%{NUMBER:bytes;long}|-)"); + Grok grok = + compiler.compile( + "%{IPORHOST:clientip} %{USER:ident;boolean} %{USER:auth}" + + " \\[%{HTTPDATE:timestamp;date;dd/MMM/yyyy:HH:mm:ss Z}\\]" + + " \"(?:%{WORD:verb;string} %{NOTSPACE:request}(?:" + + " HTTP/%{NUMBER:httpversion;float})?|%{DATA:rawrequest})\" %{NUMBER:response;int}" + + " (?:%{NUMBER:bytes;long}|-)"); System.out.println(line); Match gm = grok.match(line); @@ -61,17 +61,17 @@ public void test002_httpd_access_semi() throws GrokException { assertEquals(map.get("httpversion"), 1.1f); assertEquals(map.get("bytes"), 12846L); assertEquals("GET", map.get("verb")); - } @Test public void test002_httpd_access_colon() throws GrokException { - Grok grok = compiler.compile( - "%{IPORHOST:clientip} %{USER:ident:boolean} %{USER:auth} " - + "\\[%{HTTPDATE:timestamp:date:dd/MMM/yyyy:HH:mm:ss Z}\\] \"(?:%{WORD:verb:string} " - + "%{NOTSPACE:request}" - + "(?: HTTP/%{NUMBER:httpversion:float})?|%{DATA:rawrequest})\" %{NUMBER:response:int} " - + "(?:%{NUMBER:bytes:long}|-)"); + Grok grok = + compiler.compile( + "%{IPORHOST:clientip} %{USER:ident:boolean} %{USER:auth}" + + " \\[%{HTTPDATE:timestamp:date:dd/MMM/yyyy:HH:mm:ss Z}\\]" + + " \"(?:%{WORD:verb:string} %{NOTSPACE:request}(?:" + + " HTTP/%{NUMBER:httpversion:float})?|%{DATA:rawrequest})\" %{NUMBER:response:int}" + + " (?:%{NUMBER:bytes:long}|-)"); Match gm = grok.match(line); Map map = gm.capture(); @@ -85,6 +85,5 @@ public void test002_httpd_access_colon() throws GrokException { assertEquals(map.get("httpversion"), 1.1f); assertEquals(map.get("bytes"), 12846L); assertEquals("GET", map.get("verb")); - } } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/ApacheTest.java b/common/src/test/java/org/opensearch/sql/common/grok/ApacheTest.java index 33113d1996..db420b16d3 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/ApacheTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/ApacheTest.java @@ -5,7 +5,6 @@ package org.opensearch.sql.common.grok; - import com.google.common.io.Resources; import java.io.BufferedReader; import java.io.File; @@ -65,5 +64,4 @@ public void test002_nasa_httpd_access() throws GrokException, IOException { br.close(); } } - } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/BasicTest.java b/common/src/test/java/org/opensearch/sql/common/grok/BasicTest.java index 26df7ba57e..c724b58f3e 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/BasicTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/BasicTest.java @@ -33,8 +33,7 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class BasicTest { - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); private GrokCompiler compiler; @@ -111,8 +110,8 @@ public void test005_testLoadPatternFromFile() throws IOException, GrokException public void test006_testLoadPatternFromFileIso_8859_1() throws IOException, GrokException { File temp = tempFolder.newFile("grok-tmp-pattern"); try (FileOutputStream fis = new FileOutputStream(temp); - BufferedWriter bw = new BufferedWriter( - new OutputStreamWriter(fis, StandardCharsets.ISO_8859_1))) { + BufferedWriter bw = + new BufferedWriter(new OutputStreamWriter(fis, StandardCharsets.ISO_8859_1))) { bw.write("TEST \\u2022"); } @@ -130,5 +129,4 @@ public void test007_testLoadPatternFromReader() throws IOException, GrokExceptio Grok grok = compiler.compile("%{TEST}"); assertEquals("(?\\u20AC)", grok.getNamedRegex()); } - } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/CaptureTest.java b/common/src/test/java/org/opensearch/sql/common/grok/CaptureTest.java index 1173541e16..60e2761c83 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/CaptureTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/CaptureTest.java @@ -98,7 +98,8 @@ public void test005_captureSubName() throws GrokException { Map map = match.capture(); assertEquals(1, map.size()); assertEquals("Hello", map.get(subname).toString()); - assertEquals("{abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abcdef=Hello}", + assertEquals( + "{abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abcdef=Hello}", map.toString()); } @@ -145,7 +146,8 @@ public void test008_flattenDuplicateKeys() throws GrokException { m3.captureFlattened(); fail("should report error due tu ambiguity"); } catch (RuntimeException e) { - assertThat(e.getMessage(), + assertThat( + e.getMessage(), containsString("has multiple non-null values, this is not allowed in flattened mode")); } } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/GrokDocumentationTest.java b/common/src/test/java/org/opensearch/sql/common/grok/GrokDocumentationTest.java index 22115a825f..15d450e812 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/GrokDocumentationTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/GrokDocumentationTest.java @@ -40,23 +40,43 @@ public void assureCodeInReadmeWorks() { Assertions.assertThat(capture).hasSize(22); final boolean debug = false; - final Object[] keywordArray = new Object[] {"COMBINEDAPACHELOG", - "COMMONAPACHELOG", "clientip", "ident", "auth", "timestamp", "MONTHDAY", - "MONTH", "YEAR", "TIME", "HOUR", "MINUTE", "SECOND", "INT", "verb", - "httpversion", "rawrequest", "request", "response", "bytes", "referrer", - "agent"}; + final Object[] keywordArray = + new Object[] { + "COMBINEDAPACHELOG", + "COMMONAPACHELOG", + "clientip", + "ident", + "auth", + "timestamp", + "MONTHDAY", + "MONTH", + "YEAR", + "TIME", + "HOUR", + "MINUTE", + "SECOND", + "INT", + "verb", + "httpversion", + "rawrequest", + "request", + "response", + "bytes", + "referrer", + "agent" + }; if (debug) { capture.keySet().stream().forEach(System.err::println); } - assertTrue(new HashSet(Arrays.asList(keywordArray)) - .containsAll(new HashSet(capture.keySet()))); + assertTrue( + new HashSet(Arrays.asList(keywordArray)) + .containsAll(new HashSet(capture.keySet()))); Arrays.asList(keywordArray).stream() .forEach(o -> assertThat(capture.keySet(), hasItem((String) o))); - assertThat(new HashSet(capture.keySet()), - containsInAnyOrder(keywordArray)); - assertTrue(new HashSet(capture.keySet()) - .containsAll(new HashSet(Arrays.asList(keywordArray)))); - + assertThat(new HashSet(capture.keySet()), containsInAnyOrder(keywordArray)); + assertTrue( + new HashSet(capture.keySet()) + .containsAll(new HashSet(Arrays.asList(keywordArray)))); } } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/GrokTest.java b/common/src/test/java/org/opensearch/sql/common/grok/GrokTest.java index b5e8366807..862f9b8195 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/GrokTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/GrokTest.java @@ -37,7 +37,6 @@ import org.junit.runners.MethodSorters; import org.opensearch.sql.common.grok.exception.GrokException; - @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GrokTest { @@ -138,7 +137,6 @@ public void test002_numbers() { Match gm = grok.match("-42"); Map map = gm.capture(); assertEquals("{NUMBER=-42}", map.toString()); - } @Test @@ -152,7 +150,6 @@ public void test003_word() { gm = grok.match("abc"); map = gm.capture(); assertEquals("{WORD=abc}", map.toString()); - } @Test @@ -162,7 +159,6 @@ public void test004_space() { Match gm = grok.match("abc dc"); Map map = gm.capture(); assertEquals("{SPACE=}", map.toString()); - } @Test @@ -172,7 +168,6 @@ public void test004_number() { Match gm = grok.match("Something costs $55.4!"); Map map = gm.capture(); assertEquals("{NUMBER=55.4}", map.toString()); - } @Test @@ -182,7 +177,6 @@ public void test005_notSpace() { Match gm = grok.match("abc dc"); Map map = gm.capture(); assertEquals("{NOTSPACE=abc}", map.toString()); - } @Test @@ -209,7 +203,6 @@ public void test007_uuid() { gm = grok.match("03A8413C-F604-4D21-8F4D-24B19D98B5A7"); map = gm.capture(); assertEquals("{UUID=03A8413C-F604-4D21-8F4D-24B19D98B5A7}", map.toString()); - } @Test @@ -219,7 +212,6 @@ public void test008_mac() { Match gm = grok.match("5E:FF:56:A2:AF:15"); Map map = gm.capture(); assertEquals("{MAC=5E:FF:56:A2:AF:15}", map.toString()); - } @Test @@ -241,10 +233,12 @@ public void test010_hostPort() { Match gm = grok.match("www.google.fr:80"); Map map = gm.capture(); - assertEquals(ImmutableMap.of( - "HOSTPORT", "www.google.fr:80", - "IPORHOST", "www.google.fr", - "PORT", "80"), map); + assertEquals( + ImmutableMap.of( + "HOSTPORT", "www.google.fr:80", + "IPORHOST", "www.google.fr", + "PORT", "80"), + map); } @Test @@ -267,10 +261,11 @@ public void test011_combineApache() { assertEquals(map.get("TIME").toString(), "01:36:30"); gm = - grok.match("112.169.19.192 - - [06/Mar/2013:01:36:30 +0900] \"GET " - + "/wp-content/plugins/easy-table/themes/default/style.css?ver=1.0 HTTP/1.1\" " - + "304 - \"http://www.nflabs.com/\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) " - + "AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22\""); + grok.match( + "112.169.19.192 - - [06/Mar/2013:01:36:30 +0900] \"GET" + + " /wp-content/plugins/easy-table/themes/default/style.css?ver=1.0 HTTP/1.1\" 304" + + " - \"http://www.nflabs.com/\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2)" + + " AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22\""); map = gm.capture(); assertEquals( map.get("agent").toString(), @@ -278,7 +273,8 @@ public void test011_combineApache() { + "Chrome/25.0.1364.152 Safari/537.22"); assertEquals(map.get("clientip").toString(), "112.169.19.192"); assertEquals(map.get("httpversion").toString(), "1.1"); - assertEquals(map.get("request").toString(), + assertEquals( + map.get("request").toString(), "/wp-content/plugins/easy-table/themes/default/style.css?ver=1.0"); assertEquals(map.get("TIME").toString(), "01:36:30"); } @@ -319,7 +315,7 @@ public void test013_IpSet() throws Throwable { Grok grok = compiler.compile("%{IP}"); try (FileReader fr = new FileReader(Resources.getResource(ResourceManager.IP).getFile()); - BufferedReader br = new BufferedReader(fr)) { + BufferedReader br = new BufferedReader(fr)) { String line; System.out.println("Starting test with ip"); while ((line = br.readLine()) != null) { @@ -336,10 +332,31 @@ public void test014_month() { Grok grok = compiler.compile("%{MONTH}"); - String[] months = - {"Jan", "January", "Feb", "February", "Mar", "March", "Apr", "April", "May", "Jun", "June", - "Jul", "July", "Aug", "August", "Sep", "September", "Oct", "October", "Nov", - "November", "Dec", "December"}; + String[] months = { + "Jan", + "January", + "Feb", + "February", + "Mar", + "March", + "Apr", + "April", + "May", + "Jun", + "June", + "Jul", + "July", + "Aug", + "August", + "Sep", + "September", + "Oct", + "October", + "Nov", + "November", + "Dec", + "December" + }; int counter = 0; for (String month : months) { Match match = grok.match(month); @@ -355,20 +372,21 @@ public void test015_iso8601() throws GrokException { Grok grok = compiler.compile("%{TIMESTAMP_ISO8601}"); String[] times = { - "2001-01-01T00:00:00", - "1974-03-02T04:09:09", - "2010-05-03T08:18:18+00:00", - "2004-07-04T12:27:27-00:00", - "2001-09-05T16:36:36+0000", - "2001-11-06T20:45:45-0000", - "2001-12-07T23:54:54Z", - "2001-01-01T00:00:00.123456", - "1974-03-02T04:09:09.123456", - "2010-05-03T08:18:18.123456+00:00", - "2004-07-04T12:27:27.123456-00:00", - "2001-09-05T16:36:36.123456+0000", - "2001-11-06T20:45:45.123456-0000", - "2001-12-07T23:54:54.123456Z"}; + "2001-01-01T00:00:00", + "1974-03-02T04:09:09", + "2010-05-03T08:18:18+00:00", + "2004-07-04T12:27:27-00:00", + "2001-09-05T16:36:36+0000", + "2001-11-06T20:45:45-0000", + "2001-12-07T23:54:54Z", + "2001-01-01T00:00:00.123456", + "1974-03-02T04:09:09.123456", + "2010-05-03T08:18:18.123456+00:00", + "2004-07-04T12:27:27.123456-00:00", + "2001-09-05T16:36:36.123456+0000", + "2001-11-06T20:45:45.123456-0000", + "2001-12-07T23:54:54.123456Z" + }; int counter = 0; for (String time : times) { @@ -385,33 +403,34 @@ public void test016_uri() throws GrokException { Grok grok = compiler.compile("%{URI}"); String[] uris = { - "http://www.google.com", - "telnet://helloworld", - "http://www.example.com/", - "http://www.example.com/test.html", - "http://www.example.com/test.html?foo=bar", - "http://www.example.com/test.html?foo=bar&fizzle=baz", - "http://www.example.com:80/test.html?foo=bar&fizzle=baz", - "https://www.example.com:443/test.html?foo=bar&fizzle=baz", - "https://user@www.example.com:443/test.html?foo=bar&fizzle=baz", - "https://user:pass@somehost/fetch.pl", - "puppet:///", - "http://www.foo.com", - "http://www.foo.com/", - "http://www.foo.com/?testing", - "http://www.foo.com/?one=two", - "http://www.foo.com/?one=two&foo=bar", - "foo://somehost.com:12345", - "foo://user@somehost.com:12345", - "foo://user@somehost.com:12345/", - "foo://user@somehost.com:12345/foo.bar/baz/fizz", - "foo://user@somehost.com:12345/foo.bar/baz/fizz?test", - "foo://user@somehost.com:12345/foo.bar/baz/fizz?test=1&sink&foo=4", - "http://www.google.com/search?hl=en&source=hp&q=hello+world+%5E%40%23%24&btnG=Google+Search", - "http://www.freebsd.org/cgi/url.cgi?ports/sysutils/grok/pkg-descr", - "http://www.google.com/search?q=CAPTCHA+ssh&start=0&ie=utf-8&oe=utf-8&client=firefox-a" - + "&rls=org.mozilla:en-US:official", - "svn+ssh://somehost:12345/testing"}; + "http://www.google.com", + "telnet://helloworld", + "http://www.example.com/", + "http://www.example.com/test.html", + "http://www.example.com/test.html?foo=bar", + "http://www.example.com/test.html?foo=bar&fizzle=baz", + "http://www.example.com:80/test.html?foo=bar&fizzle=baz", + "https://www.example.com:443/test.html?foo=bar&fizzle=baz", + "https://user@www.example.com:443/test.html?foo=bar&fizzle=baz", + "https://user:pass@somehost/fetch.pl", + "puppet:///", + "http://www.foo.com", + "http://www.foo.com/", + "http://www.foo.com/?testing", + "http://www.foo.com/?one=two", + "http://www.foo.com/?one=two&foo=bar", + "foo://somehost.com:12345", + "foo://user@somehost.com:12345", + "foo://user@somehost.com:12345/", + "foo://user@somehost.com:12345/foo.bar/baz/fizz", + "foo://user@somehost.com:12345/foo.bar/baz/fizz?test", + "foo://user@somehost.com:12345/foo.bar/baz/fizz?test=1&sink&foo=4", + "http://www.google.com/search?hl=en&source=hp&q=hello+world+%5E%40%23%24&btnG=Google+Search", + "http://www.freebsd.org/cgi/url.cgi?ports/sysutils/grok/pkg-descr", + "http://www.google.com/search?q=CAPTCHA+ssh&start=0&ie=utf-8&oe=utf-8&client=firefox-a" + + "&rls=org.mozilla:en-US:official", + "svn+ssh://somehost:12345/testing" + }; int counter = 0; for (String uri : uris) { @@ -429,10 +448,7 @@ public void test017_nonMachingList() throws GrokException { Grok grok = compiler.compile("%{URI}"); String[] uris = { - "http://www.google.com", - "telnet://helloworld", - "", - "svn+ssh://somehost:12345/testing" + "http://www.google.com", "telnet://helloworld", "", "svn+ssh://somehost:12345/testing" }; int counter = 0; @@ -458,9 +474,7 @@ public void test018_namedOnlySimpleCase() throws GrokException { String text = "<< barfoobarfoo >>"; Match match = grok.match(text); Map map = match.capture(); - assertEquals("unable to parse: " + text, - text, - map.get("text")); + assertEquals("unable to parse: " + text, text, map.get("text")); } @Test @@ -488,9 +502,7 @@ private void testPatternRepetitions(boolean namedOnly, String pattern) throws Gr private void assertMatches(String description, Grok grok, String text) { Match match = grok.match(text); Map map = match.capture(); - assertEquals(format("%s: unable to parse '%s'", description, text), - text, - map.get("text")); + assertEquals(format("%s: unable to parse '%s'", description, text), text, map.get("text")); } @Test @@ -630,8 +642,8 @@ public void createGrokWithDefaultPatterns() throws GrokException { compiler.compile("%{USERNAME}", false); } - private void ensureAbortsWithDefinitionMissing(String pattern, String compilePattern, - boolean namedOnly) { + private void ensureAbortsWithDefinitionMissing( + String pattern, String compilePattern, boolean namedOnly) { try { compiler.compile(pattern); compiler.compile(compilePattern, namedOnly); @@ -643,10 +655,11 @@ private void ensureAbortsWithDefinitionMissing(String pattern, String compilePat @Test public void testGroupTypes() { - Grok grok = compiler.compile( - "%{HTTPDATE:timestamp;date;dd/MMM/yyyy:HH:mm:ss Z} %{USERNAME:username:text} " - + "%{IPORHOST:host}:%{POSINT:port:integer}", - true); + Grok grok = + compiler.compile( + "%{HTTPDATE:timestamp;date;dd/MMM/yyyy:HH:mm:ss Z} %{USERNAME:username:text} " + + "%{IPORHOST:host}:%{POSINT:port:integer}", + true); assertEquals(Converter.Type.DATETIME, grok.groupTypes.get("timestamp")); assertEquals(Converter.Type.STRING, grok.groupTypes.get("username")); assertEquals(Converter.Type.INT, grok.groupTypes.get("port")); @@ -667,8 +680,8 @@ public void testTimeZone() { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss"); Grok grok = compiler.compile("%{DATESTAMP:timestamp;date;MM/dd/yyyy HH:mm:ss}", true); Instant instant = (Instant) grok.match(date).capture().get("timestamp"); - assertEquals(ZonedDateTime.parse(date, dtf.withZone(ZoneOffset.systemDefault())).toInstant(), - instant); + assertEquals( + ZonedDateTime.parse(date, dtf.withZone(ZoneOffset.systemDefault())).toInstant(), instant); // set default timezone to PST ZoneId pst = ZoneId.of("PST", ZoneId.SHORT_IDS); diff --git a/common/src/test/java/org/opensearch/sql/common/grok/MessagesTest.java b/common/src/test/java/org/opensearch/sql/common/grok/MessagesTest.java index 98cbb3aaeb..930da8caa8 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/MessagesTest.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/MessagesTest.java @@ -16,7 +16,6 @@ import org.junit.Test; import org.opensearch.sql.common.grok.exception.GrokException; - public class MessagesTest { @Test @@ -26,8 +25,9 @@ public void test001_linux_messages() throws GrokException, IOException { Grok grok = compiler.compile("%{MESSAGESLOG}"); - BufferedReader br = new BufferedReader( - new FileReader(Resources.getResource(ResourceManager.MESSAGES).getFile())); + BufferedReader br = + new BufferedReader( + new FileReader(Resources.getResource(ResourceManager.MESSAGES).getFile())); String line; System.out.println("Starting test with linux messages log -- may take a while"); while ((line = br.readLine()) != null) { @@ -38,5 +38,4 @@ public void test001_linux_messages() throws GrokException, IOException { } br.close(); } - } diff --git a/common/src/test/java/org/opensearch/sql/common/grok/ResourceManager.java b/common/src/test/java/org/opensearch/sql/common/grok/ResourceManager.java index a13a72cd00..fba64b59d3 100644 --- a/common/src/test/java/org/opensearch/sql/common/grok/ResourceManager.java +++ b/common/src/test/java/org/opensearch/sql/common/grok/ResourceManager.java @@ -5,9 +5,7 @@ package org.opensearch.sql.common.grok; -/** - * {@code ResourceManager} . - */ +/** {@code ResourceManager} . */ public final class ResourceManager { public static final String PATTERNS = "patterns/patterns"; From 762e797fb54e2dd57565430f9e3bd7c3161f4178 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Thu, 3 Aug 2023 15:51:33 -0700 Subject: [PATCH 2/4] Igoring checkstyle for common Signed-off-by: Mitchell Gale --- common/build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/build.gradle b/common/build.gradle index 0367035ce2..25cdcd6566 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -31,6 +31,11 @@ repositories { mavenCentral() } +// Being ignored as a temporary measure before being removed in favour of +// spotless https://github.com/opensearch-project/sql/issues/1101 +checkstyleTest.ignoreFailures = true +checkstyleMain.ignoreFailures = true + dependencies { api "org.antlr:antlr4-runtime:4.7.1" api group: 'com.google.guava', name: 'guava', version: '32.0.1-jre' @@ -62,4 +67,4 @@ configurations.all { resolutionStrategy.force "org.apache.httpcomponents:httpcore:4.4.13" resolutionStrategy.force "joda-time:joda-time:2.10.12" resolutionStrategy.force "org.slf4j:slf4j-api:1.7.36" -} \ No newline at end of file +} From 9a01d9d2732d47d0adde844720d44502e8c65c78 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Fri, 4 Aug 2023 08:51:49 -0700 Subject: [PATCH 3/4] Spotless apply on string utils, Signed-off-by: Mitchell Gale --- .../java/org/opensearch/sql/common/utils/StringUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java b/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java index 87b0ad3c29..4b7752a9de 100644 --- a/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java +++ b/common/src/main/java/org/opensearch/sql/common/utils/StringUtils.java @@ -13,9 +13,9 @@ public class StringUtils { /** * Unquote Identifier which has " or ' as mark. Strings quoted by ' or " with two of these quotes * appearing next to each other in the quote acts as an escape
- * Example: 'Test''s' will result in - * 'Test's', similar with those single quotes being replaced with double quote. Supports escaping - * quotes (single/double) and escape characters using the `\` characters. + * Example: 'Test''s' will result in 'Test's', similar with those single quotes being replaced + * with double quote. Supports escaping quotes (single/double) and escape characters using the `\` + * characters. * * @param text string * @return An unquoted string whose outer pair of (single/double) quotes have been removed From baacd66536326f116351e4c98faf3d8c9149ca02 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 10 Aug 2023 12:48:59 -0700 Subject: [PATCH 4/4] Typo fix Signed-off-by: Yury-Fridlyand --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 42a1e393e7..4f5813fb22 100644 --- a/build.gradle +++ b/build.gradle @@ -84,9 +84,9 @@ repositories { spotless { java { target fileTree('.') { - include 'datasources/**/*.java', - 'core/**/*.java', - 'common/**/*.java' + include 'common/**/*.java', + 'datasources/**/*.java', + 'core/**/*.java' exclude '**/build/**', '**/build-*/**' } importOrder()