|
@@ -49,18 +49,16 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String text = randomAlphaOfLength(20);
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties("text", null, explicitSourceSetting ? indexProps : null);
|
|
|
index("{\"text_field\":\"" + text + "\"}");
|
|
|
-
|
|
|
+
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", "text_field", "text", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", "text_field", "text", JDBCType.VARCHAR, Integer.MAX_VALUE)));
|
|
|
expected.put("rows", singletonList(singletonList(text)));
|
|
|
assertResponse(expected, runSql(query));
|
|
|
} else {
|
|
@@ -80,10 +78,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
boolean ignoreAbove = randomBoolean();
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (ignoreAbove) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -91,14 +89,12 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("ignore_above", 10);
|
|
|
fieldProps.put("keyword_field", fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties("keyword", fieldProps, explicitSourceSetting ? indexProps : null);
|
|
|
index("{\"keyword_field\":\"" + keyword + "\"}");
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", "keyword_field", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", "keyword_field", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)));
|
|
|
expected.put("rows", singletonList(singletonList(ignoreAbove ? null : keyword)));
|
|
|
assertResponse(expected, runSql("SELECT keyword_field FROM test"));
|
|
|
}
|
|
@@ -114,10 +110,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
// _source for `constant_keyword` fields doesn't matter, as they should be taken from docvalue_fields
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (randomBoolean()) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -125,14 +121,15 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("value", value);
|
|
|
fieldProps.put("constant_keyword_field", fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties("constant_keyword", fieldProps, explicitSourceSetting ? indexProps : null);
|
|
|
index("{\"constant_keyword_field\":\"" + value + "\"}");
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", "constant_keyword_field", "constant_keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(columnInfo("plain", "constant_keyword_field", "constant_keyword", JDBCType.VARCHAR, Integer.MAX_VALUE))
|
|
|
+ );
|
|
|
expected.put("rows", singletonList(singletonList(value)));
|
|
|
assertResponse(expected, runSql("SELECT constant_keyword_field FROM test"));
|
|
|
}
|
|
@@ -145,15 +142,16 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
public void testFractionsForNonFloatingPointTypes() throws IOException {
|
|
|
String floatingPointNumber = "123.456";
|
|
|
String fieldType = randomFrom("long", "integer", "short", "byte");
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties(fieldType, null, null);
|
|
|
index("{\"" + fieldType + "_field\":\"" + floatingPointNumber + "\"}");
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", fieldType + "_field", fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
-
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(columnInfo("plain", fieldType + "_field", fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE))
|
|
|
+ );
|
|
|
+
|
|
|
// because "coerce" is true, a "123.456" floating point number STRING should be converted to 123, no matter the numeric field type
|
|
|
expected.put("rows", singletonList(singletonList(123)));
|
|
|
assertResponse(expected, runSql("SELECT " + fieldType + "_field FROM test"));
|
|
@@ -169,7 +167,7 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String floatingPointNumber = "123.456";
|
|
|
String fieldType = randomFrom("double", "float", "half_float", "scaled_float");
|
|
|
boolean isScaledFloat = fieldType == "scaled_float";
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (isScaledFloat) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -177,20 +175,27 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("scaling_factor", 10); // scaling_factor is required for "scaled_float"
|
|
|
fieldProps.put(fieldType + "_field", fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties(fieldType, fieldProps, null);
|
|
|
// important here is to pass floatingPointNumber as a string: "float_field": "123.456"
|
|
|
index("{\"" + fieldType + "_field\":\"" + floatingPointNumber + "\"}");
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", fieldType + "_field", fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
-
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(columnInfo("plain", fieldType + "_field", fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE))
|
|
|
+ );
|
|
|
+
|
|
|
// because "coerce" is true, a "123.456" floating point number STRING should be converted to 123.456 as number
|
|
|
// and converted to 123.5 for "scaled_float" type
|
|
|
- expected.put("rows", singletonList(singletonList(
|
|
|
- isScaledFloat ? 123.5 : (fieldType != "double" ? Double.valueOf(123.456f) : Double.valueOf(floatingPointNumber)))));
|
|
|
+ expected.put(
|
|
|
+ "rows",
|
|
|
+ singletonList(
|
|
|
+ singletonList(
|
|
|
+ isScaledFloat ? 123.5 : (fieldType != "double" ? Double.valueOf(123.456f) : Double.valueOf(floatingPointNumber))
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
assertResponse(expected, runSql("SELECT " + fieldType + "_field FROM test"));
|
|
|
}
|
|
|
|
|
@@ -237,7 +242,7 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
// Integers for short and byte values
|
|
|
testField("byte", ((Number) randomByte()).intValue());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void testField(String fieldType, Object value) throws IOException {
|
|
|
String fieldName = fieldType + "_field";
|
|
|
String query = "SELECT " + fieldName + " FROM test";
|
|
@@ -245,10 +250,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
boolean ignoreMalformed = randomBoolean(); // ignore_malformed is true, thus test a non-number value
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (ignoreMalformed) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -258,15 +263,13 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProps.put(fieldName, fieldProp);
|
|
|
actualValue = "\"foo\"";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties(fieldType, fieldProps, explicitSourceSetting ? indexProps : null);
|
|
|
index("{\"" + fieldName + "\":" + actualValue + "}");
|
|
|
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", fieldName, fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", fieldName, fieldType, jdbcTypeFor(fieldType), Integer.MAX_VALUE)));
|
|
|
expected.put("rows", singletonList(singletonList(ignoreMalformed ? null : actualValue)));
|
|
|
assertResponse(expected, runSql(query));
|
|
|
} else {
|
|
@@ -285,22 +288,20 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
boolean asString = randomBoolean(); // pass true or false as string "true" or "false
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties("boolean", null, explicitSourceSetting ? indexProps : null);
|
|
|
if (asString) {
|
|
|
index("{\"boolean_field\":\"" + booleanField + "\"}");
|
|
|
} else {
|
|
|
index("{\"boolean_field\":" + booleanField + "}");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", "boolean_field", "boolean", JDBCType.BOOLEAN, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", "boolean_field", "boolean", JDBCType.BOOLEAN, Integer.MAX_VALUE)));
|
|
|
// adding the boolean as a String here because parsing the response will yield a "true"/"false" String
|
|
|
expected.put("rows", singletonList(singletonList(asString ? String.valueOf(booleanField) : booleanField)));
|
|
|
assertResponse(expected, runSql(query));
|
|
@@ -319,18 +320,16 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String ipField = "192.168.1.1";
|
|
|
boolean explicitSourceSetting = randomBoolean(); // default (no _source setting) or explicit setting
|
|
|
boolean enableSource = randomBoolean(); // enable _source at index level
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndProperties("ip", null, explicitSourceSetting ? indexProps : null);
|
|
|
index("{\"ip_field\":\"" + ipField + "\"}");
|
|
|
-
|
|
|
+
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", "ip_field", "ip", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", "ip_field", "ip", JDBCType.VARCHAR, Integer.MAX_VALUE)));
|
|
|
expected.put("rows", singletonList(singletonList(ipField)));
|
|
|
assertResponse(expected, runSql(query));
|
|
|
} else {
|
|
@@ -353,16 +352,19 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
*/
|
|
|
public void testAliasFromDocValueField() throws IOException {
|
|
|
String keyword = randomAlphaOfLength(20);
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndAlias("keyword", null, null);
|
|
|
index("{\"keyword_field\":\"" + keyword + "\"}");
|
|
|
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", "keyword_field", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "keyword_field_alias", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "a.b.c.keyword_field_alias", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
expected.put("rows", singletonList(Arrays.asList(keyword, keyword, keyword)));
|
|
|
assertResponse(expected, runSql("SELECT keyword_field, keyword_field_alias, a.b.c.keyword_field_alias FROM test"));
|
|
|
}
|
|
@@ -382,16 +384,19 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
*/
|
|
|
public void testAliasFromSourceField() throws IOException {
|
|
|
String text = randomAlphaOfLength(20);
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndAlias("text", null, null);
|
|
|
index("{\"text_field\":\"" + text + "\"}");
|
|
|
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", "text_field", "text", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "text_field_alias", "text", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "a.b.c.text_field_alias", "text", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
expected.put("rows", singletonList(Arrays.asList(text, null, null)));
|
|
|
assertResponse(expected, runSql("SELECT text_field, text_field_alias, a.b.c.text_field_alias FROM test"));
|
|
|
}
|
|
@@ -411,16 +416,19 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
*/
|
|
|
public void testAliasAggregatableFromSourceField() throws IOException {
|
|
|
int number = randomInt();
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndAlias("integer", null, null);
|
|
|
index("{\"integer_field\":" + number + "}");
|
|
|
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", "integer_field", "integer", JDBCType.INTEGER, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "integer_field_alias", "integer", JDBCType.INTEGER, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", "a.b.c.integer_field_alias", "integer", JDBCType.INTEGER, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
expected.put("rows", singletonList(Arrays.asList(number, null, number)));
|
|
|
assertResponse(expected, runSql("SELECT integer_field, integer_field_alias, a.b.c.integer_field_alias FROM test"));
|
|
|
}
|
|
@@ -445,10 +453,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String fieldName = "text_field";
|
|
|
String subFieldName = "text_field.keyword_subfield";
|
|
|
String query = "SELECT " + fieldName + "," + subFieldName + " FROM test";
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> subFieldsProps = null;
|
|
|
if (ignoreAbove) {
|
|
|
subFieldsProps = new HashMap<>(1);
|
|
@@ -456,27 +464,28 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("ignore_above", 10);
|
|
|
subFieldsProps.put(subFieldName, fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndSubFields("text", null, explicitSourceSetting ? indexProps : null, subFieldsProps, "keyword");
|
|
|
index("{\"" + fieldName + "\":\"" + text + "\"}");
|
|
|
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", fieldName, "text", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", subFieldName, "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
|
|
|
expected.put("rows", singletonList(Arrays.asList(text, ignoreAbove ? null : text)));
|
|
|
assertResponse(expected, runSql(query));
|
|
|
} else {
|
|
|
expectSourceDisabledError(query);
|
|
|
-
|
|
|
+
|
|
|
// even if the _source is disabled, selecting only the keyword sub-field should work as expected
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
- columnInfo("plain", subFieldName, "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ expected.put("columns", Arrays.asList(columnInfo("plain", subFieldName, "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE)));
|
|
|
|
|
|
expected.put("rows", singletonList(singletonList(ignoreAbove ? null : text)));
|
|
|
assertResponse(expected, runSql("SELECT text_field.keyword_subfield FROM test"));
|
|
@@ -502,11 +511,11 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
Object actualValue = number;
|
|
|
String fieldName = "text_field";
|
|
|
String subFieldName = "text_field.integer_subfield";
|
|
|
- String query = "SELECT " + fieldName + "," + subFieldName +" FROM test";
|
|
|
-
|
|
|
+ String query = "SELECT " + fieldName + "," + subFieldName + " FROM test";
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> subFieldsProps = null;
|
|
|
if (ignoreMalformed) {
|
|
|
subFieldsProps = new HashMap<>(1);
|
|
@@ -516,16 +525,19 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
subFieldsProps.put(subFieldName, fieldProp);
|
|
|
actualValue = "foo";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndSubFields("text", null, explicitSourceSetting ? indexProps : null, subFieldsProps, "integer");
|
|
|
index("{\"" + fieldName + "\":\"" + actualValue + "\"}");
|
|
|
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", fieldName, "text", JDBCType.VARCHAR, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", subFieldName, "integer", JDBCType.INTEGER, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
if (ignoreMalformed) {
|
|
|
expected.put("rows", singletonList(Arrays.asList("foo", null)));
|
|
|
} else {
|
|
@@ -559,11 +571,11 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
Object actualValue = number;
|
|
|
String fieldName = "integer_field";
|
|
|
String subFieldName = "integer_field." + (isKeyword ? "keyword_subfield" : "text_subfield");
|
|
|
- String query = "SELECT " + fieldName + "," + subFieldName +" FROM test";
|
|
|
-
|
|
|
+ String query = "SELECT " + fieldName + "," + subFieldName + " FROM test";
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (ignoreMalformed) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -573,17 +585,25 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProps.put(fieldName, fieldProp);
|
|
|
actualValue = "foo";
|
|
|
}
|
|
|
-
|
|
|
- createIndexWithFieldTypeAndSubFields("integer", fieldProps, explicitSourceSetting ? indexProps : null, null,
|
|
|
- isKeyword ? "keyword" : "text");
|
|
|
+
|
|
|
+ createIndexWithFieldTypeAndSubFields(
|
|
|
+ "integer",
|
|
|
+ fieldProps,
|
|
|
+ explicitSourceSetting ? indexProps : null,
|
|
|
+ null,
|
|
|
+ isKeyword ? "keyword" : "text"
|
|
|
+ );
|
|
|
index("{\"" + fieldName + "\":\"" + actualValue + "\"}");
|
|
|
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", fieldName, "integer", JDBCType.INTEGER, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", subFieldName, isKeyword ? "keyword" : "text", JDBCType.VARCHAR, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
if (ignoreMalformed) {
|
|
|
expected.put("rows", singletonList(Arrays.asList(null, "foo")));
|
|
|
} else {
|
|
@@ -609,7 +629,7 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
expectSourceDisabledError("SELECT " + fieldName + " FROM test");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* "integer_field": {
|
|
|
* "type": "integer",
|
|
@@ -632,10 +652,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String fieldName = "integer_field";
|
|
|
String subFieldName = "integer_field.byte_subfield";
|
|
|
String query = "SELECT " + fieldName + "," + subFieldName + " FROM test";
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (rootIgnoreMalformed) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -650,15 +670,18 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("ignore_malformed", true);
|
|
|
subFieldProps.put(subFieldName, fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndSubFields("integer", fieldProps, explicitSourceSetting ? indexProps : null, subFieldProps, "byte");
|
|
|
index("{\"" + fieldName + "\":" + number + "}");
|
|
|
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", fieldName, "integer", JDBCType.INTEGER, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", subFieldName, "byte", JDBCType.TINYINT, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
if (isByte || subFieldIgnoreMalformed) {
|
|
|
expected.put("rows", singletonList(Arrays.asList(number, isByte ? number : null)));
|
|
@@ -698,10 +721,10 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
String fieldName = "byte_field";
|
|
|
String subFieldName = "byte_field.integer_subfield";
|
|
|
String query = "SELECT " + fieldName + "," + subFieldName + " FROM test";
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> indexProps = new HashMap<>(1);
|
|
|
indexProps.put("_source", enableSource);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Map<String, Object>> fieldProps = null;
|
|
|
if (rootIgnoreMalformed) {
|
|
|
fieldProps = new HashMap<>(1);
|
|
@@ -716,15 +739,18 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
fieldProp.put("ignore_malformed", true);
|
|
|
subFieldProps.put(subFieldName, fieldProp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createIndexWithFieldTypeAndSubFields("byte", fieldProps, explicitSourceSetting ? indexProps : null, subFieldProps, "integer");
|
|
|
index("{\"" + fieldName + "\":" + number + "}");
|
|
|
|
|
|
Map<String, Object> expected = new HashMap<>();
|
|
|
- expected.put("columns", Arrays.asList(
|
|
|
+ expected.put(
|
|
|
+ "columns",
|
|
|
+ Arrays.asList(
|
|
|
columnInfo("plain", fieldName, "byte", JDBCType.TINYINT, Integer.MAX_VALUE),
|
|
|
columnInfo("plain", subFieldName, "integer", JDBCType.INTEGER, Integer.MAX_VALUE)
|
|
|
- ));
|
|
|
+ )
|
|
|
+ );
|
|
|
if (explicitSourceSetting == false || enableSource) {
|
|
|
if (isByte || rootIgnoreMalformed) {
|
|
|
expected.put("rows", singletonList(Arrays.asList(isByte ? number : null, number)));
|
|
@@ -748,77 +774,96 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
return Collections.emptyMap();
|
|
|
}, containsString("unable to fetch fields from _source field: _source is disabled in the mappings for index [test]"));
|
|
|
}
|
|
|
-
|
|
|
- private void createIndexWithFieldTypeAndAlias(String type, Map<String, Map<String, Object>> fieldProps,
|
|
|
- Map<String, Object> indexProps) throws IOException {
|
|
|
+
|
|
|
+ private void createIndexWithFieldTypeAndAlias(String type, Map<String, Map<String, Object>> fieldProps, Map<String, Object> indexProps)
|
|
|
+ throws IOException {
|
|
|
createIndexWithFieldTypeAndProperties(type, fieldProps, indexProps, true, false, null);
|
|
|
}
|
|
|
-
|
|
|
- private void createIndexWithFieldTypeAndProperties(String type, Map<String, Map<String, Object>> fieldProps,
|
|
|
- Map<String, Object> indexProps) throws IOException {
|
|
|
+
|
|
|
+ private void createIndexWithFieldTypeAndProperties(
|
|
|
+ String type,
|
|
|
+ Map<String, Map<String, Object>> fieldProps,
|
|
|
+ Map<String, Object> indexProps
|
|
|
+ ) throws IOException {
|
|
|
createIndexWithFieldTypeAndProperties(type, fieldProps, indexProps, false, false, null);
|
|
|
}
|
|
|
-
|
|
|
- private void createIndexWithFieldTypeAndSubFields(String type, Map<String, Map<String, Object>> fieldProps,
|
|
|
- Map<String, Object> indexProps, Map<String, Map<String, Object>> subFieldsProps,
|
|
|
- String... subFieldsTypes) throws IOException {
|
|
|
+
|
|
|
+ private void createIndexWithFieldTypeAndSubFields(
|
|
|
+ String type,
|
|
|
+ Map<String, Map<String, Object>> fieldProps,
|
|
|
+ Map<String, Object> indexProps,
|
|
|
+ Map<String, Map<String, Object>> subFieldsProps,
|
|
|
+ String... subFieldsTypes
|
|
|
+ ) throws IOException {
|
|
|
createIndexWithFieldTypeAndProperties(type, fieldProps, indexProps, false, true, subFieldsProps, subFieldsTypes);
|
|
|
}
|
|
|
-
|
|
|
- private void createIndexWithFieldTypeAndProperties(String type, Map<String, Map<String, Object>> fieldProps,
|
|
|
- Map<String, Object> indexProps, boolean withAlias, boolean withSubFields, Map<String, Map<String, Object>> subFieldsProps,
|
|
|
- String... subFieldsTypes) throws IOException {
|
|
|
- Request request = new Request("PUT", "/test");
|
|
|
+
|
|
|
+ private void createIndexWithFieldTypeAndProperties(
|
|
|
+ String type,
|
|
|
+ Map<String, Map<String, Object>> fieldProps,
|
|
|
+ Map<String, Object> indexProps,
|
|
|
+ boolean withAlias,
|
|
|
+ boolean withSubFields,
|
|
|
+ Map<String, Map<String, Object>> subFieldsProps,
|
|
|
+ String... subFieldsTypes
|
|
|
+ ) throws IOException {
|
|
|
+ Request request = new Request("PUT", "/test");
|
|
|
XContentBuilder index = JsonXContent.contentBuilder().prettyPrint().startObject();
|
|
|
|
|
|
- index.startObject("mappings"); {
|
|
|
+ index.startObject("mappings");
|
|
|
+ {
|
|
|
if (indexProps != null) {
|
|
|
for (Entry<String, Object> prop : indexProps.entrySet()) {
|
|
|
if (prop.getValue() instanceof Boolean) {
|
|
|
- index.startObject(prop.getKey()); {
|
|
|
+ index.startObject(prop.getKey());
|
|
|
+ {
|
|
|
index.field("enabled", prop.getValue());
|
|
|
}
|
|
|
index.endObject();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- index.startObject("properties"); {
|
|
|
+ index.startObject("properties");
|
|
|
+ {
|
|
|
String fieldName = type + "_field";
|
|
|
- index.startObject(fieldName); {
|
|
|
+ index.startObject(fieldName);
|
|
|
+ {
|
|
|
index.field("type", type);
|
|
|
if (fieldProps != null && fieldProps.containsKey(fieldName)) {
|
|
|
for (Entry<String, Object> prop : fieldProps.get(fieldName).entrySet()) {
|
|
|
index.field(prop.getKey(), prop.getValue());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (withSubFields) {
|
|
|
index.startObject("fields");
|
|
|
- for (String subFieldType : subFieldsTypes) {
|
|
|
- String subFieldName = subFieldType + "_subfield";
|
|
|
- String fullSubFieldName = fieldName + "." + subFieldName;
|
|
|
- index.startObject(subFieldName);
|
|
|
- index.field("type", subFieldType);
|
|
|
- if (subFieldsProps != null && subFieldsProps.containsKey(fullSubFieldName)) {
|
|
|
- for (Entry<String, Object> prop : subFieldsProps.get(fullSubFieldName).entrySet()) {
|
|
|
- index.field(prop.getKey(), prop.getValue());
|
|
|
- }
|
|
|
- }
|
|
|
- index.endObject();
|
|
|
+ for (String subFieldType : subFieldsTypes) {
|
|
|
+ String subFieldName = subFieldType + "_subfield";
|
|
|
+ String fullSubFieldName = fieldName + "." + subFieldName;
|
|
|
+ index.startObject(subFieldName);
|
|
|
+ index.field("type", subFieldType);
|
|
|
+ if (subFieldsProps != null && subFieldsProps.containsKey(fullSubFieldName)) {
|
|
|
+ for (Entry<String, Object> prop : subFieldsProps.get(fullSubFieldName).entrySet()) {
|
|
|
+ index.field(prop.getKey(), prop.getValue());
|
|
|
+ }
|
|
|
}
|
|
|
+ index.endObject();
|
|
|
+ }
|
|
|
index.endObject();
|
|
|
}
|
|
|
}
|
|
|
index.endObject();
|
|
|
-
|
|
|
+
|
|
|
if (withAlias) {
|
|
|
// create two aliases - one within a hierarchy, the other just a simple field w/o hierarchy
|
|
|
- index.startObject(fieldName + "_alias"); {
|
|
|
+ index.startObject(fieldName + "_alias");
|
|
|
+ {
|
|
|
index.field("type", "alias");
|
|
|
index.field("path", fieldName);
|
|
|
}
|
|
|
index.endObject();
|
|
|
- index.startObject("a.b.c." + fieldName + "_alias"); {
|
|
|
+ index.startObject("a.b.c." + fieldName + "_alias");
|
|
|
+ {
|
|
|
index.field("type", "alias");
|
|
|
index.field("path", fieldName);
|
|
|
}
|
|
@@ -833,7 +878,7 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
request.setJsonEntity(Strings.toString(index));
|
|
|
client().performRequest(request);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Request buildRequest(String query) {
|
|
|
Request request = new Request("POST", RestSqlTestCase.SQL_QUERY_REST_ENDPOINT);
|
|
|
request.addParameter("error_trace", "true");
|
|
@@ -842,16 +887,16 @@ public abstract class FieldExtractorTestCase extends BaseRestSqlTestCase {
|
|
|
|
|
|
return request;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Map<String, Object> runSql(String query) throws IOException {
|
|
|
Response response = client().performRequest(buildRequest(query));
|
|
|
try (InputStream content = response.getEntity().getContent()) {
|
|
|
return XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private JDBCType jdbcTypeFor(String esType) {
|
|
|
- switch(esType) {
|
|
|
+ switch (esType) {
|
|
|
case "long":
|
|
|
return JDBCType.BIGINT;
|
|
|
case "integer":
|