提交 4412a506 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not cast rows to arrays in TABLE function

上级 157a2622
......@@ -5211,11 +5211,13 @@ SELECT X, SET(@I, IFNULL(@I, 0)+X) RUNNING_TOTAL FROM SYSTEM_RANGE(1, 10)
"
"Functions (System)","TABLE","
{ TABLE | TABLE_DISTINCT } ( { name dataType = expression } [,...] )
{ TABLE | TABLE_DISTINCT }
( { name dataType = array|rowValueExpression } [,...] )
","
Returns the result set. TABLE_DISTINCT removes duplicate rows.
","
SELECT * FROM TABLE(ID INT=(1, 2), NAME VARCHAR=('Hello', 'World'))
SELECT * FROM TABLE(VALUE INT = ARRAY[1, 2]);
SELECT * FROM TABLE(ID INT=(1, 2), NAME VARCHAR=('Hello', 'World'));
"
"Functions (System)","TRANSACTION_ID","
......
......@@ -16,7 +16,7 @@ import org.h2.message.DbException;
import org.h2.result.LocalResult;
import org.h2.table.Column;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueCollectionBase;
import org.h2.value.ValueInt;
import org.h2.value.ValueNull;
import org.h2.value.ValueResultSet;
......@@ -105,8 +105,11 @@ public class TableFunction extends Function {
if (v == ValueNull.INSTANCE) {
list[i] = new Value[0];
} else {
ValueArray array = (ValueArray) v.convertTo(Value.ARRAY);
Value[] l = array.getList();
int type = v.getType();
if (type != Value.ARRAY && type != Value.ROW) {
v = v.convertTo(Value.ARRAY);
}
Value[] l = ((ValueCollectionBase) v).getList();
list[i] = l;
rows = Math.max(rows, l.length);
}
......
......@@ -61,10 +61,6 @@ public class ValueArray extends ValueCollectionBase {
return (ValueArray) EMPTY;
}
public Value[] getList() {
return values;
}
@Override
public int getType() {
return Value.ARRAY;
......
......@@ -14,7 +14,7 @@ import org.h2.util.MathUtils;
/**
* Base class for ARRAY and ROW values.
*/
abstract class ValueCollectionBase extends Value {
public abstract class ValueCollectionBase extends Value {
final Value[] values;
......@@ -24,6 +24,10 @@ abstract class ValueCollectionBase extends Value {
this.values = values;
}
public Value[] getList() {
return values;
}
@Override
public int hashCode() {
if (hash != 0) {
......
......@@ -47,10 +47,6 @@ public class ValueRow extends ValueCollectionBase {
return (ValueRow) EMPTY;
}
public Value[] getList() {
return values;
}
@Override
public int getType() {
return Value.ROW;
......
......@@ -34,6 +34,9 @@ drop table test;
explain select * from table(id int = (1, 2), name varchar=('Hello', 'World'));
>> SELECT TABLE.ID, TABLE.NAME FROM TABLE(ID INT=ROW (1, 2), NAME VARCHAR=ROW ('Hello', 'World')) /* function */
explain select * from table(id int = ARRAY[1, 2], name varchar=ARRAY['Hello', 'World']);
>> SELECT TABLE.ID, TABLE.NAME FROM TABLE(ID INT=ARRAY [1, 2], NAME VARCHAR=ARRAY ['Hello', 'World']) /* function */
select * from table(id int=(1, 2), name varchar=('Hello', 'World')) x order by id;
> ID NAME
> -- -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论