Skip to content

Commit bc062bb

Browse files
committed
rebase
1 parent 30c05df commit bc062bb

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

native/spark-expr/src/static_invoke/char_varchar_utils/read_side_padding.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ fn spark_read_side_padding2(
100100
truncate,
101101
ColumnarValue::Scalar(ScalarValue::Int32(Some(*length))),
102102
string,
103-
is_left_pad
103+
is_left_pad,
104104
),
105105
DataType::LargeUtf8 => spark_read_side_padding_internal::<i64>(
106106
array,
107107
truncate,
108108
ColumnarValue::Scalar(ScalarValue::Int32(Some(*length))),
109109
string,
110-
is_left_pad
110+
is_left_pad,
111111
),
112112
// Dictionary support required for SPARK-48498
113113
DataType::Dictionary(_, value_type) => {
@@ -268,15 +268,13 @@ fn add_padding_string(
268268
} else {
269269
Ok(string)
270270
}
271-
} else if is_left_pad {
272-
println!("is lpad so flipping padding and the string");
273-
let pad_needed = length - char_len;
274-
let pad: String = pad_string.chars().cycle().take(pad_needed).collect();
275-
Ok(format!("{}{}", pad, string))
276271
} else {
277272
let pad_needed = length - char_len;
278273
let pad: String = pad_string.chars().cycle().take(pad_needed).collect();
279-
Ok(string + &pad)
280-
274+
if is_left_pad {
275+
Ok(format!("{}{}", pad, string))
276+
} else {
277+
Ok(string + &pad)
278+
}
281279
}
282280
}

spark/src/main/scala/org/apache/comet/serde/strings.scala

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,11 @@ object CometStringLPad extends CometExpressionSerde[StringLPad] {
189189
expr: StringLPad,
190190
inputs: Seq[Attribute],
191191
binding: Boolean): Option[Expr] = {
192-
expr.pad match {
193-
case Literal(str, DataTypes.StringType) if str.toString == " " =>
194-
scalarFunctionExprToProto(
195-
"lpad",
196-
exprToProtoInternal(expr.str, inputs, binding),
197-
exprToProtoInternal(expr.len, inputs, binding))
198-
case _ =>
199-
withInfo(expr, "StringLPad with non-space characters is not supported")
200-
None
201-
}
192+
scalarFunctionExprToProto(
193+
"lpad",
194+
exprToProtoInternal(expr.str, inputs, binding),
195+
exprToProtoInternal(expr.len, inputs, binding),
196+
exprToProtoInternal(expr.pad, inputs, binding))
202197
}
203198
}
204199

spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,24 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
425425
}
426426
}
427427

428+
test("test lpad expression support") {
429+
val data = Seq(("IfIWasARoadIWouldBeBent", 10), ("తెలుగు", 2))
430+
withParquetTable(data, "t1") {
431+
val res = sql("select lpad(_1,_2) , lpad(_1,2) from t1 order by _1")
432+
checkSparkAnswerAndOperator(res)
433+
}
434+
}
435+
436+
test("LPAD with character support other than default space") {
437+
val data = Seq(("IfIWasARoadIWouldBeBent", 10), ("hi", 2))
438+
withParquetTable(data, "t1") {
439+
val res = sql(
440+
""" select lpad(_1,_2,'?'), lpad(_1,_2,'??') , lpad(_1,2, '??'), hex(lpad(unhex('aabb'), 5)),
441+
rpad(_1, 5, '??') from t1 order by _1 """.stripMargin)
442+
checkSparkAnswerAndOperator(res)
443+
}
444+
}
445+
428446
test("dictionary arithmetic") {
429447
// TODO: test ANSI mode
430448
withSQLConf(SQLConf.ANSI_ENABLED.key -> "false", "parquet.enable.dictionary" -> "true") {

0 commit comments

Comments
 (0)