forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
- Loading branch information
1 parent
662a938
commit f335101
Showing
7 changed files
with
204 additions
and
24 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
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
66 changes: 66 additions & 0 deletions
66
opensearch/src/main/java/org/opensearch/sql/opensearch/mapping/MappingEntry.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,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.opensearch.mapping; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.opensearch.common.time.DateFormatter; | ||
import org.opensearch.sql.data.type.ExprType; | ||
|
||
@AllArgsConstructor | ||
public class MappingEntry { | ||
|
||
@Getter | ||
private String fieldType; | ||
|
||
@Getter | ||
private String formats; | ||
|
||
@Getter | ||
@Setter | ||
private ExprType dataType; | ||
|
||
public MappingEntry(String fieldType) { | ||
this(fieldType, null, null); | ||
} | ||
|
||
public List<String> getFormatList() { | ||
if (formats == null || formats.isEmpty()) { | ||
return List.of(); | ||
} | ||
return Arrays.stream(formats.split("\\|\\|")).map(String::trim).collect(Collectors.toList()); | ||
} | ||
|
||
public List<DateFormatter> getNamedFormatters() { | ||
return getFormatList().stream().filter(f -> { | ||
try { | ||
DateTimeFormatter.ofPattern(f); | ||
return false; | ||
} catch (Exception e) { | ||
return true; | ||
} | ||
}) | ||
.map(DateFormatter::forPattern).collect(Collectors.toList()); | ||
} | ||
|
||
public List<DateTimeFormatter> getRegularFormatters() { | ||
return getFormatList().stream().map(f -> { | ||
try { | ||
return DateTimeFormatter.ofPattern(f); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull).collect(Collectors.toList()); | ||
} | ||
} |
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