Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-48372][SPARK-45716][PYTHON] Implement StructType.treeString #46685

Closed
wants to merge 3 commits into from

Conversation

zhengruifeng
Copy link
Contributor

What changes were proposed in this pull request?

Implement StructType.treeString

Why are the changes needed?

feature parity, this method is Scala-only before

Does this PR introduce any user-facing change?

yes

In [2]: schema1 = DataType.fromDDL("c1 INT, c2 STRUCT<c3: INT, c4: STRUCT<c5: INT, c6: INT>>")

In [3]: print(schema1.treeString())
root
 |-- c1: integer (nullable = true)
 |-- c2: struct (nullable = true)
 |    |-- c3: integer (nullable = true)
 |    |-- c4: struct (nullable = true)
 |    |    |-- c5: integer (nullable = true)
 |    |    |-- c6: integer (nullable = true)

How was this patch tested?

added tests

Was this patch authored or co-authored using generative AI tooling?

no

@xinrong-meng
Copy link
Member

LGTM thank you!

I found https://issues.apache.org/jira/browse/SPARK-45716 which we might want to close together later.

@zhengruifeng zhengruifeng changed the title [SPARK-48372][PYTHON] Implement StructType.treeString [SPARK-48372][SPARK-45716][PYTHON] Implement StructType.treeString May 22, 2024
@zhengruifeng
Copy link
Contributor Author

thanks, merged to master

@zhengruifeng zhengruifeng deleted the py_tree_string branch May 22, 2024 07:32
zhengruifeng added a commit that referenced this pull request May 23, 2024
…ypes

### What changes were proposed in this pull request?
this PR is a follow up of #46685.

### Why are the changes needed?
`StructType.treeString` uses `DataType.typeName` to generate the tree string, however, the `typeName` in python is a class method and can not return the same string for parameterized types.

```
In [2]: schema = StructType().add("c", CharType(10), True).add("v", VarcharType(10), True).add("d", DecimalType(10, 2), True).add("ym00", YearM
   ...: onthIntervalType(0, 0)).add("ym01", YearMonthIntervalType(0, 1)).add("ym11", YearMonthIntervalType(1, 1))

In [3]: print(schema.treeString())
root
 |-- c: char (nullable = true)
 |-- v: varchar (nullable = true)
 |-- d: decimal (nullable = true)
 |-- ym00: yearmonthinterval (nullable = true)
 |-- ym01: yearmonthinterval (nullable = true)
 |-- ym11: yearmonthinterval (nullable = true)
```

it should be
```
In [4]: print(schema.treeString())
root
 |-- c: char(10) (nullable = true)
 |-- v: varchar(10) (nullable = true)
 |-- d: decimal(10,2) (nullable = true)
 |-- ym00: interval year (nullable = true)
 |-- ym01: interval year to month (nullable = true)
 |-- ym11: interval month (nullable = true)
```

### Does this PR introduce _any_ user-facing change?
no, this feature was just added and not release out yet.

### How was this patch tested?
added tests

### Was this patch authored or co-authored using generative AI tooling?
no

Closes #46711 from zhengruifeng/tree_string_fix.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
zhengruifeng added a commit that referenced this pull request Jun 11, 2024
…thod

### What changes were proposed in this pull request?
followup of #46685, to remove unused helper method

### Why are the changes needed?
method `_tree_string` is no longer needed

### Does this PR introduce _any_ user-facing change?
No, internal change only

### How was this patch tested?
CI

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #46936 from zhengruifeng/tree_string_followup.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants