[fix](ip) fix ip type in IndexDef support (#50637)
### What problem does this PR solve? only in branch-2.1 we do not support old indexDef to support Ip type and fix array_contains && arrays_overlap for with type array<ip> which backport: https://github.com/apache/doris/pull/50637 Issue Number: close #xxx
This commit is contained in:
@ -225,7 +225,7 @@ public class IndexDef {
|
||||
}
|
||||
if (!(colType.isDateType() || colType.isDecimalV2Type() || colType.isDecimalV3Type()
|
||||
|| colType.isFixedPointType() || colType.isStringType() || colType == PrimitiveType.BOOLEAN
|
||||
|| colType.isVariantType()) || colType.isIPType()) {
|
||||
|| colType.isVariantType() || colType.isIPType())) {
|
||||
throw new AnalysisException(colType + " is not supported in " + indexType.toString() + " index. "
|
||||
+ "invalid index: " + indexName);
|
||||
}
|
||||
|
||||
@ -17,9 +17,13 @@
|
||||
|
||||
package org.apache.doris.analysis;
|
||||
|
||||
import org.apache.doris.catalog.ArrayType;
|
||||
import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.KeysType;
|
||||
import org.apache.doris.catalog.MapType;
|
||||
import org.apache.doris.catalog.PrimitiveType;
|
||||
import org.apache.doris.catalog.ScalarType;
|
||||
import org.apache.doris.catalog.StructType;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -75,6 +79,65 @@ public class IndexDefTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexType() {
|
||||
// support types
|
||||
PrimitiveType[] supportedTypes = new PrimitiveType[] {
|
||||
PrimitiveType.DATE, PrimitiveType.DATETIME, PrimitiveType.DATEV2, PrimitiveType.DATETIMEV2,
|
||||
PrimitiveType.DECIMALV2, PrimitiveType.DECIMAL32, PrimitiveType.DECIMAL64, PrimitiveType.DECIMAL128, PrimitiveType.DECIMAL256,
|
||||
PrimitiveType.TINYINT, PrimitiveType.SMALLINT, PrimitiveType.INT, PrimitiveType.BIGINT, PrimitiveType.LARGEINT,
|
||||
PrimitiveType.VARCHAR, PrimitiveType.CHAR, PrimitiveType.STRING,
|
||||
PrimitiveType.BOOLEAN,
|
||||
PrimitiveType.IPV4, PrimitiveType.IPV6
|
||||
};
|
||||
for (PrimitiveType type : supportedTypes) {
|
||||
try {
|
||||
IndexDef def = new IndexDef("idx", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "");
|
||||
Column col = new Column("col1", type);
|
||||
def.checkColumn(col, KeysType.DUP_KEYS, true, true);
|
||||
// check in array
|
||||
def.checkColumn(new Column("col1", ArrayType.create(ScalarType.createType(type), true)), KeysType.DUP_KEYS, true, true);
|
||||
} catch (AnalysisException e) {
|
||||
Assert.fail("Should support type: " + type + ", but got: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
// not support types
|
||||
PrimitiveType[] unsupportedTypes = new PrimitiveType[] {
|
||||
PrimitiveType.FLOAT, PrimitiveType.DOUBLE,
|
||||
PrimitiveType.INVALID_TYPE, PrimitiveType.NULL_TYPE,
|
||||
PrimitiveType.HLL, PrimitiveType.BITMAP, PrimitiveType.QUANTILE_STATE,
|
||||
PrimitiveType.TIME, PrimitiveType.TIMEV2, PrimitiveType.JSONB,
|
||||
PrimitiveType.LAMBDA_FUNCTION, PrimitiveType.ALL
|
||||
};
|
||||
for (PrimitiveType type : unsupportedTypes) {
|
||||
try {
|
||||
IndexDef def = new IndexDef("idx", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "");
|
||||
Column col = new Column("col1", type);
|
||||
def.checkColumn(col, KeysType.DUP_KEYS, true, true);
|
||||
Assert.fail("Should not support type: " + type);
|
||||
} catch (AnalysisException e) {
|
||||
Assert.assertTrue(e.getMessage().contains("is not supported"));
|
||||
}
|
||||
}
|
||||
// check in map/struct
|
||||
try {
|
||||
IndexDef def = new IndexDef("idx", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "");
|
||||
Column col = new Column("col1", new MapType(ScalarType.createType(PrimitiveType.INT), ScalarType.createType(PrimitiveType.STRING)));
|
||||
def.checkColumn(col, KeysType.DUP_KEYS, true, true);
|
||||
Assert.fail("Should not support map type");
|
||||
} catch (AnalysisException e) {
|
||||
Assert.assertTrue(e.getMessage().contains("is not supported"));
|
||||
}
|
||||
try {
|
||||
IndexDef def = new IndexDef("idx", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "");
|
||||
Column col = new Column("col1", new StructType(ScalarType.createType(PrimitiveType.INT), ScalarType.createType(PrimitiveType.STRING)), true);
|
||||
def.checkColumn(col, KeysType.DUP_KEYS, true, true);
|
||||
Assert.fail("Should not support map type");
|
||||
} catch (AnalysisException e) {
|
||||
Assert.assertTrue(e.getMessage().contains("is not supported"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toSql() {
|
||||
Assert.assertEquals("INDEX `index1` (`col1`) USING INVERTED COMMENT 'balabala'", def.toSql());
|
||||
|
||||
Reference in New Issue
Block a user