Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into integ-datetime-now
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Aug 17, 2022
1 parent 974b352 commit 4a6a9be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableMap;
import org.json.JSONArray;
import java.time.LocalTime;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.common.utils.StringUtils;
Expand Down Expand Up @@ -659,7 +660,22 @@ public void testNowLikeFunctions() throws IOException {
}
}
}

TimeZone.setDefault(testTz);
}

@Test
public void testMakeTime() throws IOException {
var result = executeQuery(String.format(
"source=%s | eval f1 = MAKETIME(20, 30, 40), f2 = MAKETIME(20.2, 49.5, 42.100502) | fields f1, f2", TEST_INDEX_DATE));
verifySchema(result, schema("f1", null, "time"), schema("f2", null, "time"));
verifySome(result.getJSONArray("datarows"), rows("20:30:40", "20:50:42.100502"));
}

@Test
public void testMakeDate() throws IOException {
var result = executeQuery(String.format(
"source=%s | eval f1 = MAKEDATE(1945, 5.9), f2 = MAKEDATE(1984, 1984) | fields f1, f2", TEST_INDEX_DATE));
verifySchema(result, schema("f1", null, "date"), schema("f2", null, "date"));
verifySome(result.getJSONArray("datarows"), rows("1945-01-06", "1989-06-06"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_PEOPLE2;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE;
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.schema;
Expand Down Expand Up @@ -644,10 +645,25 @@ public void testNowLikeFunctions() throws IOException {
}
}
}

TimeZone.setDefault(testTz);
}

@Test
public void testMakeTime() throws IOException {
var result = executeQuery(String.format(
"select MAKETIME(20, 30, 40) as f1, MAKETIME(20.2, 49.5, 42.100502) as f2", TEST_INDEX_DATE));
verifySchema(result, schema("MAKETIME(20, 30, 40)", "f1", "time"), schema("MAKETIME(20.2, 49.5, 42.100502)", "f2", "time"));
verifySome(result.getJSONArray("datarows"), rows("20:30:40", "20:50:42.100502"));
}

@Test
public void testMakeDate() throws IOException {
var result = executeQuery(String.format(
"select MAKEDATE(1945, 5.9) as f1, MAKEDATE(1984, 1984) as f2", TEST_INDEX_DATE));
verifySchema(result, schema("MAKEDATE(1945, 5.9)", "f1", "date"), schema("MAKEDATE(1984, 1984)", "f2", "date"));
verifySome(result.getJSONArray("datarows"), rows("1945-01-06", "1989-06-06"));
}

protected JSONObject executeQuery(String query) throws IOException {
Request request = new Request("POST", QUERY_API_ENDPOINT);
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
reportError(channel, e, isClientError(e) ? BAD_REQUEST : SERVICE_UNAVAILABLE);
}
});

} catch (Exception e) {
logAndPublishMetrics(e);
return channel -> reportError(channel, e, isClientError(e) ? BAD_REQUEST : SERVICE_UNAVAILABLE);
Expand Down
2 changes: 2 additions & 0 deletions ppl/src/main/antlr/OpenSearchPPLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ MAKEDATE: 'MAKEDATE';
MAKETIME: 'MAKETIME';
LOCALTIME: 'LOCALTIME';
LOCALTIMESTAMP: 'LOCALTIMESTAMP';
MAKEDATE: 'MAKEDATE';
MAKETIME: 'MAKETIME';
MONTHNAME: 'MONTHNAME';
NOW: 'NOW';
SUBDATE: 'SUBDATE';
Expand Down

0 comments on commit 4a6a9be

Please sign in to comment.