This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add date and time support * update doc * update doc
- Loading branch information
Showing
19 changed files
with
706 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprDateValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.data.model; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprCoreType; | ||
import com.amazon.opendistroforelasticsearch.sql.exception.SemanticCheckException; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Date Value. | ||
*/ | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
public class ExprDateValue implements ExprValue { | ||
/** | ||
* todo. only support UTC now. | ||
*/ | ||
private static final ZoneId ZONE = ZoneId.of("UTC"); | ||
private final Instant date; | ||
|
||
/** | ||
* Constructor of ExprDateValue. | ||
*/ | ||
public ExprDateValue(String date) { | ||
try { | ||
LocalDate localDate = LocalDate.parse(date); | ||
this.date = localDate.atStartOfDay(ZONE).toInstant(); | ||
} catch (DateTimeParseException e) { | ||
throw new SemanticCheckException(String.format("date:%s in unsupported format, please use " | ||
+ "yyyy-MM-dd", date)); | ||
} | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return DateTimeFormatter.ISO_LOCAL_DATE.withZone(ZONE).format(date); | ||
} | ||
|
||
@Override | ||
public ExprCoreType type() { | ||
return ExprCoreType.DATE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("DATE '%s'", value()); | ||
} | ||
|
||
public ZonedDateTime getDate() { | ||
return date.atZone(ZONE); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTimeValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.data.model; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprCoreType; | ||
import com.amazon.opendistroforelasticsearch.sql.exception.SemanticCheckException; | ||
import java.time.LocalTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Time Value. | ||
*/ | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
public class ExprTimeValue implements ExprValue { | ||
/** | ||
* todo. only support UTC now. | ||
*/ | ||
private static final ZoneId ZONE = ZoneId.of("UTC"); | ||
private final LocalTime time; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public ExprTimeValue(String time) { | ||
try { | ||
this.time = LocalTime.parse(time); | ||
} catch (DateTimeParseException e) { | ||
throw new SemanticCheckException(String.format("time:%s in unsupported format, please use " | ||
+ "HH:mm:ss", time)); | ||
} | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return DateTimeFormatter.ISO_LOCAL_TIME.withZone(ZONE).format(time); | ||
} | ||
|
||
@Override | ||
public ExprCoreType type() { | ||
return ExprCoreType.TIME; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("TIME '%s'", value()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...rc/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTimestampValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.data.model; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprCoreType; | ||
import com.amazon.opendistroforelasticsearch.sql.exception.SemanticCheckException; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.time.temporal.ChronoUnit; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Timestamp Value. | ||
*/ | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
public class ExprTimestampValue implements ExprValue { | ||
/** | ||
* todo. only support UTC now. | ||
*/ | ||
private static final ZoneId ZONE = ZoneId.of("UTC"); | ||
/** | ||
* todo. only support timestamp in format yyyy-MM-dd HH:mm:ss. | ||
*/ | ||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter | ||
.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
private final Instant timestamp; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public ExprTimestampValue(String timestamp) { | ||
try { | ||
this.timestamp = LocalDateTime.parse(timestamp, FORMATTER).atZone(ZONE).toInstant(); | ||
} catch (DateTimeParseException e) { | ||
throw new SemanticCheckException(String.format("timestamp:%s in unsupported format, please " | ||
+ "use yyyy-MM-dd HH:mm:ss", timestamp)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public String value() { | ||
return FORMATTER.withZone(ZONE).format(timestamp.truncatedTo(ChronoUnit.SECONDS)); | ||
} | ||
|
||
@Override | ||
public ExprCoreType type() { | ||
return ExprCoreType.TIMESTAMP; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("TIMESTAMP '%s'", value()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.