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

SNOW-859689: DataFrame from flatten() function returns wrong schema() #41

Open
martin-frydl opened this issue Jul 10, 2023 · 2 comments

Comments

@martin-frydl
Copy link

I have following code in Java:

        DataFrame orig = session.sql("SELECT 'a b c' AS SEQ");
        for (StructField f : orig.schema().fields()) {
            System.out.println("ORIG: " + f.name());
        }
        Column split = functions.callBuiltin("split", (Seq<Object>)(Seq<?>)JavaConverters.collectionAsScalaIterable(Arrays.asList(orig.col("SEQ"), functions.lit(" "))).toSeq());
        DataFrame flat = orig.flatten(split, "", true, false, "ARRAY");
        for (StructField f : flat.schema().fields()) {
            System.out.println("FLAT: " + f.name());
        }
        flat.explain();
        Row[] rows = flat.collect();

Here I create DataFrame from which I build another one using flatten() function. In original data frame there is a column SEQ which conflict with the same column generated by flatten. So Snowpark renames my column to some generated name. However, schema() called upon the flatten data frame does not return this name, it returns the original one. As a result, there are two SEQ columns returned. In previous versions of Snowpark like 1.6.2, this worked fine, schema was correct.

1.8.0 returns:

ORIG: SEQ <--- orig frame, just one column
FLAT: SEQ <---- SEQ as copy of original in flattened data frame
FLAT: SEQ <---- SEQ from flatten + other column from flatten
FLAT: KEY
FLAT: PATH
FLAT: INDEX
FLAT: VALUE
FLAT: THIS

The query is:

SELECT * FROM (
   -- Here SEQ is renamed
   SELECT  "SEQ" AS "a_4gKh_SEQ" FROM (
        SELECT 'a b c' AS SEQ
    )
), LATERAL FLATTEN (
   -- renamed column here
    INPUT => split("a_4gKh_SEQ", ' '),
    PATH => '', OUTER => true, RECURSIVE => false, MODE => 'ARRAY'
  )

In older Snowpark it printed something like this:

ORIG: SEQ <----------------- SEQ in orig frame
FLAT: "a_0uEn_SEQ" <---- renamed SEQ
FLAT: SEQ <------------------ SEQ from flatten
FLAT: KEY
FLAT: PATH
FLAT: INDEX
FLAT: VALUE
FLAT: THIS
@github-actions github-actions bot changed the title DataFrame from flatten() function returns wrong schema() SNOW-859689: DataFrame from flatten() function returns wrong schema() Jul 10, 2023
@martin-frydl
Copy link
Author

Seems like using output() instead of schema() gives correct names but I have no idea what is that function doing. I was not able to find any documentation and even the code (scala is quite a mystery for me, no 'def output' found by grep).

@sfc-gh-jfreeberg
Copy link
Collaborator

Possibly related to #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants