Skip to content

Commit

Permalink
Fix cast double
Browse files Browse the repository at this point in the history
Signed-off-by: Jiao Mingye <mxdzs0612@gmail.com>
  • Loading branch information
mxdzs0612 committed Mar 22, 2024
1 parent 76ee018 commit d4bf703
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import com.starrocks.analysis.SlotRef;
import com.starrocks.analysis.TableName;
import com.starrocks.analysis.TypeDef;
import com.starrocks.catalog.HiveTable;
import com.starrocks.catalog.IcebergTable;
import com.starrocks.catalog.KeysType;
import com.starrocks.catalog.OlapTable;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.TableFunctionTable;
import com.starrocks.catalog.Type;
import com.starrocks.common.Pair;
import com.starrocks.qe.ConnectContext;
Expand Down Expand Up @@ -98,7 +101,20 @@ public static void analyze(CreateTableAsSelectStmt createTableAsSelectStmt, Conn
}

for (int i = 0; i < allFields.size(); i++) {
Type type = AnalyzerUtils.transformTableColumnType(allFields.get(i).getType());
boolean isConnectorTable = false;
try {
Table connectorTable = tableRefToTable.get(allFields.get(i).getRelationAlias().getTbl());
if (connectorTable != null) {
isConnectorTable = connectorTable instanceof HiveTable
|| connectorTable instanceof TableFunctionTable
|| connectorTable instanceof IcebergTable;
}
} catch (NullPointerException ignored) {
// skip if nullPointer called
}
Type type = isConnectorTable
? AnalyzerUtils.transformTableColumnType(allFields.get(i).getType(), false)
: AnalyzerUtils.transformTableColumnType(allFields.get(i).getType());
Expr originExpression = allFields.get(i).getOriginExpression();
ColumnDef columnDef = new ColumnDef(finalColumnNames.get(i), new TypeDef(type), false,
null, originExpression.isNullable(), ColumnDef.DefaultValueDef.NOT_SET, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void testCTASPrimaryKey() throws Exception {
}

@Test
public void testCtasWithNullale() throws Exception {
public void testCtasWithNullable() throws Exception {
{
String createSql = "create table emps (\n" +
" empid int null,\n" +
Expand Down
20 changes: 19 additions & 1 deletion test/sql/test_catalog/R/test_iceberg_hadoop_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ select * from ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test;
drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test;
-- result:
-- !result
create table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double (
c0 double
);
-- result:
-- !result
create table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as as select * from ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double;
-- result:
-- !result
describe ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as;
-- result:
c0 DOUBLE Yes false None
-- !result
drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as;
-- result:
-- !result
drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double;
-- result:
-- !result
drop database ice_hadoop${uuid0}.ice_hadoop_db${uuid0};
-- result:
-- !result
Expand All @@ -41,4 +59,4 @@ shell: ossutil64 rm -rf oss://${oss_bucket}/test_catalog/test_iceberg_hadoop_cat
-- result:
0

-- !result
-- !result
12 changes: 12 additions & 0 deletions test/sql/test_catalog/T/test_iceberg_hadoop_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ select * from ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test;

drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test;

create table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double (
c0 double
);

create table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as as select * from ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double;

describe ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as;

drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double_as;

drop table ice_hadoop${uuid0}.ice_hadoop_db${uuid0}.test_double;

drop database ice_hadoop${uuid0}.ice_hadoop_db${uuid0};

drop catalog ice_hadoop${uuid0};
Expand Down

0 comments on commit d4bf703

Please sign in to comment.