Unverified 提交 cc0f5b06 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1014 from katzyn/enum

Copy enumerators from table to view
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #1012: NPE when querying INFORMATION_SCHEMA.COLUMNS on a view that references an ENUM column
</li>
<li>Issue #1010: MERGE USING table not found with qualified table <li>Issue #1010: MERGE USING table not found with qualified table
</li> </li>
<li>PR #1009: Fix ARRAY_AGG with ORDER BY and refactor aggregates <li>PR #1009: Fix ARRAY_AGG with ORDER BY and refactor aggregates
......
...@@ -186,6 +186,8 @@ public class Operation extends Expression { ...@@ -186,6 +186,8 @@ public class Operation extends Expression {
dataType = left.getType(); dataType = left.getType();
if (dataType == Value.UNKNOWN) { if (dataType == Value.UNKNOWN) {
dataType = Value.DECIMAL; dataType = Value.DECIMAL;
} else if (dataType == Value.ENUM) {
dataType = Value.INT;
} }
break; break;
case CONCAT: case CONCAT:
...@@ -315,7 +317,9 @@ public class Operation extends Expression { ...@@ -315,7 +317,9 @@ public class Operation extends Expression {
DataType.getDataType(r).name); DataType.getDataType(r).name);
} else { } else {
dataType = Value.getHigherOrder(l, r); dataType = Value.getHigherOrder(l, r);
if (DataType.isStringType(dataType) && if (dataType == Value.ENUM) {
dataType = Value.INT;
} else if (DataType.isStringType(dataType) &&
session.getDatabase().getMode().allowPlusForStringConcat) { session.getDatabase().getMode().allowPlusForStringConcat) {
opType = OpType.CONCAT; opType = OpType.CONCAT;
} }
......
...@@ -193,7 +193,13 @@ public class TableView extends Table { ...@@ -193,7 +193,13 @@ public class TableView extends Table {
long precision = expr.getPrecision(); long precision = expr.getPrecision();
int scale = expr.getScale(); int scale = expr.getScale();
int displaySize = expr.getDisplaySize(); int displaySize = expr.getDisplaySize();
Column col = new Column(name, type, precision, scale, displaySize); String[] enumerators = null;
if (type == Value.ENUM) {
if (expr instanceof ExpressionColumn) {
enumerators = ((ExpressionColumn) expr).getColumn().getEnumerators();
}
}
Column col = new Column(name, type, precision, scale, displaySize, enumerators);
col.setTable(this, i); col.setTable(this, i);
// Fetch check constraint from view column source // Fetch check constraint from view column source
ExpressionColumn fromColumn = null; ExpressionColumn fromColumn = null;
......
...@@ -185,3 +185,70 @@ SELECT * FROM TEST; ...@@ -185,3 +185,70 @@ SELECT * FROM TEST;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
CREATE TABLE TEST(E ENUM('A', 'B'));
> ok
INSERT INTO TEST VALUES ('B');
> update count: 1
CREATE VIEW V AS SELECT * FROM TEST;
> ok
SELECT * FROM V;
> E
> -
> B
> rows: 1
CREATE VIEW V1 AS SELECT E + 2 AS E FROM TEST;
> ok
SELECT * FROM V1;
> E
> -
> 3
> rows: 1
CREATE VIEW V2 AS SELECT E + E AS E FROM TEST;
> ok
SELECT * FROM V2;
> E
> -
> 2
> rows: 1
CREATE VIEW V3 AS SELECT -E AS E FROM TEST;
> ok
SELECT * FROM V3;
> E
> --
> -1
> rows: 1
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'E' ORDER BY TABLE_NAME;
> TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_PRECISION_RADIX NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME TYPE_NAME NULLABLE IS_COMPUTED SELECTIVITY CHECK_CONSTRAINT SEQUENCE_NAME REMARKS SOURCE_DATA_TYPE COLUMN_TYPE COLUMN_ON_UPDATE
> ------------- ------------ ---------- ----------- ---------------- -------------- ----------- --------- ------------------------ ---------------------- ----------------- ----------------------- ------------- ------------------ -------------- --------- -------- ----------- ----------- ---------------- ------------- ------- ---------------- ------------- ----------------
> SCRIPT PUBLIC TEST E 1 null YES 1111 2147483647 2147483647 2147483647 10 0 Unicode OFF ENUM 1 FALSE 50 null null ENUM('A','B') null
> SCRIPT PUBLIC V E 1 null YES 1111 2147483647 2147483647 2147483647 10 0 Unicode OFF ENUM 1 FALSE 50 null null ENUM('A','B') null
> SCRIPT PUBLIC V1 E 1 null YES 4 2147483647 2147483647 2147483647 10 0 Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null
> SCRIPT PUBLIC V2 E 1 null YES 4 2147483647 2147483647 2147483647 10 0 Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null
> SCRIPT PUBLIC V3 E 1 null YES 4 2147483647 2147483647 2147483647 10 0 Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null
> rows (ordered): 5
DROP VIEW V;
> ok
DROP VIEW V1;
> ok
DROP VIEW V2;
> ok
DROP VIEW V3;
> ok
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论