Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiqiang Ding authored and Yiqiang Ding committed Sep 7, 2023
1 parent fcf4d36 commit 43830c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
/**
* Copyright 2023 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.common;

import java.util.List;

import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.rel.type.StructKind;

import java.util.List;

public class CoralJavaTypeFactoryImpl extends JavaTypeFactoryImpl {
public CoralJavaTypeFactoryImpl(RelDataTypeSystem typeSystem) {
super(typeSystem);
}
public CoralJavaTypeFactoryImpl(RelDataTypeSystem typeSystem) {
super(typeSystem);
}

@Override
public RelDataType createStructType(
final List<RelDataType> typeList,
final List<String> fieldNameList) {
return createStructType(StructKind.PEEK_FIELDS, typeList, fieldNameList);
}
@Override
public RelDataType createStructType(final List<RelDataType> typeList, final List<String> fieldNameList) {
return createStructType(StructKind.PEEK_FIELDS_NO_EXPAND, typeList, fieldNameList);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017-2022 LinkedIn Corporation. All rights reserved.
* Copyright 2017-2023 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
Expand Down Expand Up @@ -121,8 +121,8 @@ public void testTableWithUnionComplex() throws Exception {
HiveToRelConverter converter = new HiveToRelConverter(mscAdapter);
RelDataType rowType2 = converter.convertSql("SELECT coalesce_struct(foo) AS bar from nested_union").getRowType();
assertNotNull(rowType2);
expectedTypeString = "RecordType(" + "RecordType(" + "INTEGER tag_0, DOUBLE tag_1, "
+ "RecordType(INTEGER a, RecordType(INTEGER tag_0, DOUBLE tag_1) b) tag_2) bar)";
expectedTypeString = "RecordType(" + "RecordType:peek_no_expand(" + "INTEGER tag_0, DOUBLE tag_1, "
+ "RecordType:peek_no_expand(INTEGER a, RecordType:peek_no_expand(INTEGER tag_0, DOUBLE tag_1) b) tag_2) bar)";
assertEquals(rowType2.toString(), expectedTypeString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.runtime.CalciteContextException;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.type.ReturnTypes;
import org.apache.calcite.sql.type.SqlTypeFamily;
Expand Down Expand Up @@ -484,15 +483,6 @@ public void testStructFieldAccess() {
}
}

// Calcite supports PEEK_FIELDS to peek into struct fields
// That is not suitable for our usecase. This test is to ensure
// we don't inadvertently introduce that change
@Test(expectedExceptions = CalciteContextException.class)
public void testStructPeekDisallowed() {
final String sql = "SELECT name from complex";
RelNode rel = toRel(sql);
}

@Test
public void testStructReturnFieldAccess() {
final String sql = "select named_struct('field_a', 10, 'field_b', 'abc').field_b";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018-2022 LinkedIn Corporation. All rights reserved.
* Copyright 2018-2023 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testLateralUDTF() {
String expectedPlan = "LogicalProject(a=[$0], col1=[$4])\n"
+ " LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{0}])\n"
+ " LogicalTableScan(table=[[hive, test, tableone]])\n"
+ " LogicalTableFunctionScan(invocation=[com.linkedin.coral.hive.hive2rel.CoralTestUDTF($cor0.a)], rowType=[RecordType(INTEGER col1)])\n";
+ " LogicalTableFunctionScan(invocation=[com.linkedin.coral.hive.hive2rel.CoralTestUDTF($cor0.a)], rowType=[RecordType:peek_no_expand(INTEGER col1)])\n";
assertEquals(RelOptUtil.toString(rel), expectedPlan);
}

Expand Down

0 comments on commit 43830c0

Please sign in to comment.