From f2d51785c9ce4d59f6bdf879191ec1c6fc32a4a3 Mon Sep 17 00:00:00 2001 From: Samrat002 Date: Sun, 11 Aug 2024 01:50:03 +0530 Subject: [PATCH] fix issue --- .../table/catalog/glue/util/GlueUtils.java | 34 +++++++++++++++---- .../catalog/glue/util/GlueUtilsTest.java | 10 +++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/flink-catalog-aws/flink-catalog-aws-glue/src/main/java/org/apache/flink/table/catalog/glue/util/GlueUtils.java b/flink-catalog-aws/flink-catalog-aws-glue/src/main/java/org/apache/flink/table/catalog/glue/util/GlueUtils.java index 78e69b10..dc1fa9b9 100644 --- a/flink-catalog-aws/flink-catalog-aws-glue/src/main/java/org/apache/flink/table/catalog/glue/util/GlueUtils.java +++ b/flink-catalog-aws/flink-catalog-aws-glue/src/main/java/org/apache/flink/table/catalog/glue/util/GlueUtils.java @@ -382,18 +382,38 @@ public static String getGlueFunctionClassName(CatalogFunction function) { * @param sb StringBuilder. * @return Derived String from {@link Expression}. */ +// public static String getExpressionString(Expression expression, StringBuilder sb) { +// +// for (Expression childExpression : expression.getChildren()) { +// if (childExpression.getChildren() != null && !childExpression.getChildren().isEmpty()) { +// getExpressionString(childExpression, sb); +// } +// } +// return sb.insert( +// 0, +// expression.asSummaryString() +// + GlueCatalogConstants.SPACE +// + GlueCatalogConstants.AND) +// .toString(); +// } public static String getExpressionString(Expression expression, StringBuilder sb) { - for (Expression childExpression : expression.getChildren()) { if (childExpression.getChildren() != null && !childExpression.getChildren().isEmpty()) { getExpressionString(childExpression, sb); } } - return sb.insert( - 0, - expression.asSummaryString() - + GlueCatalogConstants.SPACE - + GlueCatalogConstants.AND) - .toString(); + + // If the StringBuilder is not empty, append "AND " + if (sb.length() > 0) { + sb.append(GlueCatalogConstants.SPACE) + .append(GlueCatalogConstants.AND) + .append(GlueCatalogConstants.SPACE); + } + + // Append the current expression summary + sb.append(expression.asSummaryString()); + + return sb.toString(); } + } diff --git a/flink-catalog-aws/flink-catalog-aws-glue/src/test/java/org/apache/flink/table/catalog/glue/util/GlueUtilsTest.java b/flink-catalog-aws/flink-catalog-aws-glue/src/test/java/org/apache/flink/table/catalog/glue/util/GlueUtilsTest.java index 6fcb4626..99f2355c 100644 --- a/flink-catalog-aws/flink-catalog-aws-glue/src/test/java/org/apache/flink/table/catalog/glue/util/GlueUtilsTest.java +++ b/flink-catalog-aws/flink-catalog-aws-glue/src/test/java/org/apache/flink/table/catalog/glue/util/GlueUtilsTest.java @@ -18,6 +18,7 @@ package org.apache.flink.table.catalog.glue.util; +import org.apache.flink.table.api.DataTypes; import org.apache.flink.table.catalog.CatalogDatabase; import org.apache.flink.table.catalog.CatalogFunctionImpl; import org.apache.flink.table.catalog.FunctionLanguage; @@ -25,6 +26,8 @@ import org.apache.flink.table.catalog.exceptions.CatalogException; import org.apache.flink.table.catalog.glue.constants.GlueCatalogConstants; +import org.apache.flink.table.expressions.Expression; +import org.apache.flink.table.expressions.utils.ResolvedExpressionMock; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.awssdk.services.glue.model.Database; @@ -165,5 +168,10 @@ public void testExtractTableOwner() { } @Test - public void testExpressionString() {} + public void testExpressionString() { + StringBuilder sb = new StringBuilder(); + Expression expression = ResolvedExpressionMock.of(DataTypes.INT(), "column1"); + GlueUtils.getExpressionString(expression, sb); + Assertions.assertEquals( "column1", sb.toString()); + } }