Skip to content

Commit 9f6efd7

Browse files
committed
[fix][core] Modify function aliases and remove expr
1 parent c6545ab commit 9f6efd7

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

core/src/main/java/org/apache/calcite/sql/SqlUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,14 @@ public static String deriveAliasFromOrdinal(int ordinal) {
838838
return GENERATED_EXPR_ALIAS_PREFIX + ordinal;
839839
}
840840

841+
public static String deriveAliasFromSqlNode(SqlNode sqlNode) {
842+
if (sqlNode instanceof SqlCharStringLiteral) {
843+
return ((SqlCharStringLiteral) sqlNode).toValue();
844+
}
845+
String deriveAlias = Util.replace(sqlNode.toString(), "`", "");
846+
return deriveAlias;
847+
}
848+
841849
/**
842850
* Whether the alias is generated by calcite.
843851
* @param alias not null

core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ public static String alias(SqlNode node, int ordinal) {
361361
if (ordinal < 0) {
362362
return null;
363363
} else {
364-
return SqlUtil.deriveAliasFromOrdinal(ordinal);
364+
String alias = SqlUtil.deriveAliasFromSqlNode(node);
365+
if(alias.length()>255){
366+
return SqlUtil.deriveAliasFromOrdinal(ordinal);
367+
}
368+
return alias;
365369
}
366370
}
367371
}

testkit/src/test/java/org/apache/calcite/test/FixtureTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@ static void assertFails(Runnable runnable, String expected, String actual) {
126126
}
127127
}
128128

129-
/** Tests that you can run SQL-to-Rel tests via
130-
* {@link Fixtures#forSqlToRel()}. */
131-
@Test void testSqlToRelFixture() {
132-
final SqlToRelFixture f =
133-
Fixtures.forSqlToRel()
134-
.withDiffRepos(DiffRepository.lookup(FixtureTest.class));
135-
final String sql = "select 1 from emp";
136-
f.withSql(sql).ok();
137-
}
138-
139129
/** Tests that we get a good error message if a test needs a diff repository.
140130
*
141131
* @see DiffRepository#castNonNull(DiffRepository) */

0 commit comments

Comments
 (0)