Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix issue that IP type cannot pass JDBC formatter (#275)
Browse files Browse the repository at this point in the history
* Added type IP into jdbc formatter schema

* Added IT

* Updated
  • Loading branch information
chloe-zh authored Nov 8, 2019
1 parent 517362f commit a332808
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void remove() {

// Only core ES datatypes currently supported
public enum Type {
TEXT, KEYWORD, // String types
TEXT, KEYWORD, IP, // String types
LONG, INTEGER, SHORT, BYTE, DOUBLE, FLOAT, HALF_FLOAT, SCALED_FLOAT, // Numeric types
DATE, // Date types
BOOLEAN, // Boolean types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.json.JSONObject;
import org.junit.Test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;

public class JdbcTestIT extends SQLIntegTestCase {
Expand All @@ -27,6 +28,7 @@ protected void init() throws Exception {
loadIndex(Index.ONLINE);
loadIndex(Index.PEOPLE);
loadIndex(Index.ACCOUNT);
loadIndex(Index.WEBLOG);
}

public void testPercentilesQuery() {
Expand Down Expand Up @@ -126,4 +128,13 @@ public void dateFunctionNameCaseInsensitiveTest() {
"ORDER BY date_format(insert_time, 'yyyy-MM-dd', 'UTC')", "jdbc")
);
}

@Test
public void ipTypeShouldPassJdbcFormatter() {
assertThat(
executeQuery("SELECT host AS hostIP FROM " + TestsConstants.TEST_INDEX_WEBLOG
+ " ORDER BY hostIP", "jdbc"),
containsString("\"type\": \"ip\"")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ public enum Index {
ORDER(TestsConstants.TEST_INDEX_ORDER,
"_doc",
TestUtils.getOrderIndexMapping(),
"src/test/resources/order.json");
"src/test/resources/order.json"),
WEBLOG(TestsConstants.TEST_INDEX_WEBLOG,
"weblog",
TestUtils.getWeblogsIndexMapping(),
"src/test/resources/weblogs.json");

private final String name;
private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,30 @@ public static String getOrderIndexMapping() {
"}";
}

public static String getWeblogsIndexMapping() {
return "{\n" +
" \"weblog\": {\n" +
" \"properties\": {\n" +
" \"host\": {\n" +
" \"type\": \"ip\"\n" +
" },\n" +
" \"method\": {\n" +
" \"type\": \"text\"\n" +
" },\n" +
" \"url\": {\n" +
" \"type\": \"text\"\n" +
" },\n" +
" \"response\": {\n" +
" \"type\": \"text\"\n" +
" },\n" +
" \"bytes\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
}

public static void loadBulk(Client client, String jsonPath, String defaultIndex) throws Exception {
System.out.println(String.format("Loading file %s into elasticsearch cluster", jsonPath));
String absJsonPath = getResourceFilePath(jsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class TestsConstants {
public final static String TEST_INDEX_BANK = TEST_INDEX + "_bank";
public final static String TEST_INDEX_BANK_TWO = TEST_INDEX_BANK + "_two";
public final static String TEST_INDEX_ORDER = TEST_INDEX + "_order";
public final static String TEST_INDEX_WEBLOG = TEST_INDEX + "_weblog";

public final static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public final static String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/weblogs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"index":{"_type": "weblog"}}
{"host": "199.72.81.55", "method": "GET", "url": "/history/apollo/", "response": "200", "bytes": "6245"}
{"index":{"_type": "weblog"}}
{"host": "199.120.110.21", "method": "GET", "url": "/shuttle/missions/sts-73/mission-sts-73.html", "response": "200", "bytes": "4085"}
{"index":{"_type": "weblog"}}
{"host": "205.212.115.106", "method": "GET", "url": "/shuttle/countdown/countdown.html", "response": "200", "bytes": "3985"}

0 comments on commit a332808

Please sign in to comment.