Skip to content

Commit

Permalink
Merge branch 'main' into dev/sl_GoogleJavaFormat20
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale authored Aug 21, 2023
2 parents ee426c9 + 7e3a718 commit d81fc26
Show file tree
Hide file tree
Showing 264 changed files with 11,376 additions and 13,121 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/integ-tests-with-security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Security Plugin IT

on:
pull_request:
push:
branches-ignore:
- 'dependabot/**'
paths:
- 'integ-test/**'
- '.github/workflows/integ-tests-with-security.yml'

jobs:
security-it:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
java: [ 11, 17 ]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}

- name: Build with Gradle
run: ./gradlew integTestWithSecurity

- name: Upload test reports
if: ${{ always() }}
uses: actions/upload-artifact@v2
continue-on-error: true
with:
name: test-reports-${{ matrix.os }}-${{ matrix.java }}
path: |
integ-test/build/reports/**
integ-test/build/testclusters/*/logs/*
integ-test/build/testclusters/*/config/*
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Fork(value = 1)
public class ComparisonOperatorBenchmark {

@Param(value = { "int", "string", "date" })
@Param(value = {"int", "string", "date"})
private String testDataType;

private final Map<String, ExprValue> params =
Expand All @@ -65,9 +65,7 @@ public void testGreaterOperator() {

private void run(Function<Expression[], FunctionExpression> dsl) {
ExprValue param = params.get(testDataType);
FunctionExpression func = dsl.apply(new Expression[] {
literal(param), literal(param)
});
FunctionExpression func = dsl.apply(new Expression[] {literal(param), literal(param)});
func.valueOf();
}
}
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ spotless {
'spark/**/*.java',
'plugin/**/*.java',
'ppl/**/*.java',
'integ-test/**/*java'
'integ-test/**/*java',
'core/**/*.java',
'opensearch/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
package org.opensearch.sql.data.model;

import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;

import com.google.common.base.Objects;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -57,14 +56,9 @@ public LocalTime timeValue() {
return LocalTime.of(0, 0, 0);
}

@Override
public LocalDateTime datetimeValue() {
return LocalDateTime.of(date, timeValue());
}

@Override
public Instant timestampValue() {
return ZonedDateTime.of(date, timeValue(), UTC_ZONE_ID).toInstant();
return ZonedDateTime.of(date, timeValue(), ZoneOffset.UTC).toInstant();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.data.model;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand Down Expand Up @@ -35,27 +36,20 @@ public String stringValue() {
}

@Override
public LocalDateTime datetimeValue() {
public Instant timestampValue() {
try {
return new ExprDatetimeValue(value).datetimeValue();
return new ExprTimestampValue(value).timestampValue();
} catch (SemanticCheckException e) {
try {
return new ExprDatetimeValue(
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
.datetimeValue();
} catch (SemanticCheckException exception) {
throw new SemanticCheckException(
String.format(
"datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
value));
}
return new ExprTimestampValue(
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
.timestampValue();
}
}

@Override
public LocalDate dateValue() {
try {
return new ExprDatetimeValue(value).dateValue();
return new ExprTimestampValue(value).dateValue();
} catch (SemanticCheckException e) {
return new ExprDateValue(value).dateValue();
}
Expand All @@ -64,7 +58,7 @@ public LocalDate dateValue() {
@Override
public LocalTime timeValue() {
try {
return new ExprDatetimeValue(value).timeValue();
return new ExprTimestampValue(value).timeValue();
} catch (SemanticCheckException e) {
return new ExprTimeValue(value).timeValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.Objects;
Expand Down Expand Up @@ -57,12 +56,8 @@ public LocalDate dateValue(FunctionProperties functionProperties) {
return LocalDate.now(functionProperties.getQueryStartClock());
}

public LocalDateTime datetimeValue(FunctionProperties functionProperties) {
return LocalDateTime.of(dateValue(functionProperties), timeValue());
}

public Instant timestampValue(FunctionProperties functionProperties) {
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant();
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), ZoneOffset.UTC).toInstant();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITHOUT_NANO;
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
Expand All @@ -32,7 +32,7 @@ public ExprTimestampValue(String timestamp) {
try {
this.timestamp =
LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS)
.atZone(UTC_ZONE_ID)
.atZone(ZoneOffset.UTC)
.toInstant();
} catch (DateTimeParseException e) {
throw new SemanticCheckException(
Expand All @@ -42,13 +42,18 @@ public ExprTimestampValue(String timestamp) {
}
}

/** localDateTime Constructor. */
public ExprTimestampValue(LocalDateTime localDateTime) {
this.timestamp = localDateTime.atZone(ZoneOffset.UTC).toInstant();
}

@Override
public String value() {
return timestamp.getNano() == 0
? DATE_TIME_FORMATTER_WITHOUT_NANO
.withZone(UTC_ZONE_ID)
.withZone(ZoneOffset.UTC)
.format(timestamp.truncatedTo(ChronoUnit.SECONDS))
: DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(UTC_ZONE_ID).format(timestamp);
: DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(ZoneOffset.UTC).format(timestamp);
}

@Override
Expand All @@ -63,17 +68,12 @@ public Instant timestampValue() {

@Override
public LocalDate dateValue() {
return timestamp.atZone(UTC_ZONE_ID).toLocalDate();
return timestamp.atZone(ZoneOffset.UTC).toLocalDate();
}

@Override
public LocalTime timeValue() {
return timestamp.atZone(UTC_ZONE_ID).toLocalTime();
}

@Override
public LocalDateTime datetimeValue() {
return timestamp.atZone(UTC_ZONE_ID).toLocalDateTime();
return timestamp.atZone(ZoneOffset.UTC).toLocalTime();
}

@Override
Expand All @@ -88,12 +88,12 @@ public String toString() {

@Override
public int compare(ExprValue other) {
return timestamp.compareTo(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
return timestamp.compareTo(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
}

@Override
public boolean equal(ExprValue other) {
return timestamp.equals(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
return timestamp.equals(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAmount;
import java.util.List;
Expand Down Expand Up @@ -133,12 +132,6 @@ default LocalDate dateValue() {
"invalid to get dateValue from value of type " + type());
}

/** Get datetime value. */
default LocalDateTime datetimeValue() {
throw new ExpressionEvaluationException(
"invalid to get datetimeValue from value of type " + type());
}

/** Get interval value. */
default TemporalAmount intervalValue() {
throw new ExpressionEvaluationException(
Expand Down
Loading

0 comments on commit d81fc26

Please sign in to comment.