|
@@ -15,7 +15,6 @@ import org.elasticsearch.xpack.sql.expression.literal.interval.Intervals;
|
|
|
import java.sql.JDBCType;
|
|
import java.sql.JDBCType;
|
|
|
import java.sql.SQLType;
|
|
import java.sql.SQLType;
|
|
|
import java.time.OffsetTime;
|
|
import java.time.OffsetTime;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -136,7 +135,7 @@ public class SqlDataTypes {
|
|
|
ODBC_TO_ES.put("SQL_INTERVAL_MINUTE_TO_SECOND", INTERVAL_MINUTE_TO_SECOND);
|
|
ODBC_TO_ES.put("SQL_INTERVAL_MINUTE_TO_SECOND", INTERVAL_MINUTE_TO_SECOND);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static final Collection<DataType> TYPES = Stream.concat(DataTypes.types().stream(), Arrays.asList(
|
|
|
|
|
|
|
+ private static final Collection<DataType> TYPES = Stream.concat(DataTypes.types().stream(), Stream.of(
|
|
|
DATE,
|
|
DATE,
|
|
|
TIME,
|
|
TIME,
|
|
|
INTERVAL_YEAR,
|
|
INTERVAL_YEAR,
|
|
@@ -154,8 +153,7 @@ public class SqlDataTypes {
|
|
|
INTERVAL_MINUTE_TO_SECOND,
|
|
INTERVAL_MINUTE_TO_SECOND,
|
|
|
GEO_SHAPE,
|
|
GEO_SHAPE,
|
|
|
GEO_POINT,
|
|
GEO_POINT,
|
|
|
- SHAPE)
|
|
|
|
|
- .stream())
|
|
|
|
|
|
|
+ SHAPE))
|
|
|
.sorted(Comparator.comparing(DataType::typeName))
|
|
.sorted(Comparator.comparing(DataType::typeName))
|
|
|
.collect(toUnmodifiableList());
|
|
.collect(toUnmodifiableList());
|
|
|
|
|
|
|
@@ -420,13 +418,13 @@ public class SqlDataTypes {
|
|
|
*/
|
|
*/
|
|
|
public static int defaultPrecision(DataType dataType) {
|
|
public static int defaultPrecision(DataType dataType) {
|
|
|
if (dataType == UNSUPPORTED) {
|
|
if (dataType == UNSUPPORTED) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == NULL) {
|
|
if (dataType == NULL) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BOOLEAN) {
|
|
if (dataType == BOOLEAN) {
|
|
|
- return 1;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BYTE) {
|
|
if (dataType == BYTE) {
|
|
|
return 3;
|
|
return 3;
|
|
@@ -462,16 +460,16 @@ public class SqlDataTypes {
|
|
|
return 3;
|
|
return 3;
|
|
|
}
|
|
}
|
|
|
if (dataType == IP) {
|
|
if (dataType == IP) {
|
|
|
- return 39;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BINARY) {
|
|
if (dataType == BINARY) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == OBJECT) {
|
|
if (dataType == OBJECT) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == NESTED) {
|
|
if (dataType == NESTED) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
|
// SQL specific
|
|
// SQL specific
|
|
@@ -487,13 +485,13 @@ public class SqlDataTypes {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (dataType == GEO_SHAPE) {
|
|
if (dataType == GEO_SHAPE) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == GEO_POINT) {
|
|
if (dataType == GEO_POINT) {
|
|
|
return Integer.MAX_VALUE;
|
|
return Integer.MAX_VALUE;
|
|
|
}
|
|
}
|
|
|
if (dataType == SHAPE) {
|
|
if (dataType == SHAPE) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == INTERVAL_YEAR) {
|
|
if (dataType == INTERVAL_YEAR) {
|
|
|
return 7;
|
|
return 7;
|
|
@@ -540,13 +538,13 @@ public class SqlDataTypes {
|
|
|
|
|
|
|
|
public static int displaySize(DataType dataType) {
|
|
public static int displaySize(DataType dataType) {
|
|
|
if (dataType == UNSUPPORTED) {
|
|
if (dataType == UNSUPPORTED) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == NULL) {
|
|
if (dataType == NULL) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BOOLEAN) {
|
|
if (dataType == BOOLEAN) {
|
|
|
- return 1;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BYTE) {
|
|
if (dataType == BYTE) {
|
|
|
return 5;
|
|
return 5;
|
|
@@ -576,22 +574,22 @@ public class SqlDataTypes {
|
|
|
return 32766;
|
|
return 32766;
|
|
|
}
|
|
}
|
|
|
if (dataType == TEXT) {
|
|
if (dataType == TEXT) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == DATETIME) {
|
|
if (dataType == DATETIME) {
|
|
|
return 29;
|
|
return 29;
|
|
|
}
|
|
}
|
|
|
if (dataType == IP) {
|
|
if (dataType == IP) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == BINARY) {
|
|
if (dataType == BINARY) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == OBJECT) {
|
|
if (dataType == OBJECT) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == NESTED) {
|
|
if (dataType == NESTED) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
|
// SQL specific
|
|
// SQL specific
|
|
@@ -603,53 +601,17 @@ public class SqlDataTypes {
|
|
|
return 18;
|
|
return 18;
|
|
|
}
|
|
}
|
|
|
if (dataType == GEO_SHAPE) {
|
|
if (dataType == GEO_SHAPE) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
if (dataType == GEO_POINT) {
|
|
if (dataType == GEO_POINT) {
|
|
|
//2 doubles + len("POINT( )")
|
|
//2 doubles + len("POINT( )")
|
|
|
return 25 * 2 + 8;
|
|
return 25 * 2 + 8;
|
|
|
}
|
|
}
|
|
|
if (dataType == SHAPE) {
|
|
if (dataType == SHAPE) {
|
|
|
- return Integer.MAX_VALUE;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_YEAR) {
|
|
|
|
|
- return 7;
|
|
|
|
|
|
|
+ return dataType.size();
|
|
|
}
|
|
}
|
|
|
- if (dataType == INTERVAL_MONTH) {
|
|
|
|
|
- return 7;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_DAY) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_HOUR) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_MINUTE) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_SECOND) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_YEAR_TO_MONTH) {
|
|
|
|
|
- return 7;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_DAY_TO_HOUR) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_DAY_TO_MINUTE) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_DAY_TO_SECOND) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_HOUR_TO_MINUTE) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_HOUR_TO_SECOND) {
|
|
|
|
|
- return 23;
|
|
|
|
|
- }
|
|
|
|
|
- if (dataType == INTERVAL_MINUTE_TO_SECOND) {
|
|
|
|
|
- return 23;
|
|
|
|
|
|
|
+ if (SqlDataTypes.isInterval(dataType)) {
|
|
|
|
|
+ return defaultPrecision(dataType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -723,4 +685,4 @@ public class SqlDataTypes {
|
|
|
}
|
|
}
|
|
|
return displaySize(t);
|
|
return displaySize(t);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|