Skip to content

PARQUET-363: Allow empty schema groups. - #263

Closed
rdblue wants to merge 3 commits into
apache:masterfrom
rdblue:PARQUET-363-allow-empty-groups
Closed

rdblue wants to merge 3 commits into
apache:masterfrom
rdblue:PARQUET-363-allow-empty-groups

Conversation

@rdblue

@rdblue rdblue commented Aug 21, 2015

Copy link
Copy Markdown
Contributor

This removes the check added in PARQUET-278 that rejects schema groups
that have no fields. Selecting 0 columns from a file is allowed and used
by Hive and SparkSQL to implement queries like select count(1) ...

This removes the check added in PARQUET-278 that rejects schema groups
that have no fields. Selecting 0 columns from a file is allowed and used
by Hive and SparkSQL to implement queries like 'select count(1) ...'
@rdblue
rdblue force-pushed the PARQUET-363-allow-empty-groups branch from f004285 to 365f30d Compare August 21, 2015 20:28
@liancheng

Copy link
Copy Markdown
Contributor

LGTM

@isnotinvain

Copy link
Copy Markdown
Contributor

Before we ship this, can we add back in some validation to cover what PARQUET-278 intended to cover?

@isnotinvain

Copy link
Copy Markdown
Contributor

I think maybe special casing a statistics-only read path would make sense, but we do need a runtime check that there are no nested empty structs inside a schema at write time.

@isnotinvain

Copy link
Copy Markdown
Contributor

could be as simple as moving the check from the GroupType constructor to some method in the write path that just asserts (recursively) that the schema being written contains no empty GroupTypes

@rdblue

rdblue commented Sep 8, 2015

Copy link
Copy Markdown
Contributor Author

@isnotinvain PARQUET-278 doesn't state what the underlying problem was, just that we "shouldn't" allow empty groups. Was it the problem you're talking about above, where something breaks in the write path if you pass in an empty schema?

We have two options in that case, to update the write path to write nothing for empty groups (fine with me) or to add a check as you suggest when instantiating a writer. I'm fine with the latter case, since I see no value in being able to write a schema with empty groups. I'd rather not block this fix on it, though.

@isnotinvain

Copy link
Copy Markdown
Contributor

Parquet will write corrupt files if the write path accepts schemas with empty Groups, the file won't be readable after its written because of the empty groups, IIRC.

That's why the exception was added to to the constructor. I think it's important we preserve that guard, but we can certainly move it to be write-path only and out of the Group constructor. I feel like that would belong in this PR, instead of removing an important check without replacing it. What do you think?

@rdblue

rdblue commented Sep 8, 2015

Copy link
Copy Markdown
Contributor Author

Since it is a file corruption issue, we should definitely fix it in this PR. I didn't realize that files were corrupted... is there something that documents what happens and whether you can recover the files?

I'll add a write-side guard to this issue before we commit it.

@isnotinvain

Copy link
Copy Markdown
Contributor

Maybe corruption is too strong of a word. The data is all in tact, but you can't read the full records. You are probably fine if you project away the field w/ with the empty group in it, is that right @tsdeng?

This avoids writing schemas that have empty groups by checking for empty
groups when instantiating the ParquetFileWriter. This also removes the
check in the Types builders that prevents users from creating schemas
with no fields. Schemas without fields are valid read schemas (they can
be used to count) and some existing files that were written with empty
group schemas cannot be read because this check throws an exception when
reconstructing the file's schema.
@rdblue

rdblue commented Sep 10, 2015

Copy link
Copy Markdown
Contributor Author

Okay, I've updated this PR:

  • ParquetFileReader now rejects schemas with empty groups
  • Types will now construct schemas with empty groups because there may be data files where there are empty groups and this was preventing them from being read (I believe this is likely the error that @tsdeng hit).
  • I've added a few minor classes to make this easily tested, like ExampleParquetWriter.

@isnotinvain

Copy link
Copy Markdown
Contributor

Thanks for updating. The issue we had and that @tsdeng fixed was that the write path was allowing these invalid schemas through which it shouldn't. Your fix looks good to me.

@tsdeng you had some tests for each kind of group (required, optional, repeated) was there any specific reason for that? I don't think it's needed so I think we are OK.

+1

@isnotinvain

Copy link
Copy Markdown
Contributor

oh, we may also want to put this check in the outputformat so that it is checked client-side, before launching a hadoop job, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add comment on why this should be supported so next time it will not be accidentally removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rdblue

rdblue commented Sep 11, 2015

Copy link
Copy Markdown
Contributor Author

@isnotinvain, I thought about adding it to the OutputFormat, but that would require calling WriteContext.init on the client side, which isn't currently done. If we want to change the output initialization steps to catch stuff like this, I think we should do it in a separate issue.

@rdblue
rdblue force-pushed the PARQUET-363-allow-empty-groups branch from df65435 to ab370f1 Compare September 11, 2015 17:30
@isnotinvain

Copy link
Copy Markdown
Contributor

+1, yeah if we don't have access to the schema on the client without changing the lifecycle, lets do that separately if needed.

@asfgit asfgit closed this in f203d80 Sep 11, 2015
rdblue added a commit to rdblue/parquet-mr that referenced this pull request Jul 13, 2016
This removes the check added in PARQUET-278 that rejects schema groups
that have no fields. Selecting 0 columns from a file is allowed and used
by Hive and SparkSQL to implement queries like `select count(1) ...`

Author: Ryan Blue <blue@apache.org>

Closes apache#263 from rdblue/PARQUET-363-allow-empty-groups and squashes the following commits:

ab370f1 [Ryan Blue] PARQUET-363: Update Type builder tests to allow empty groups.
926932b [Ryan Blue] PARQUET-363: Add write-side schema validation.
365f30d [Ryan Blue] PARQUET-363: Allow empty schema groups.
rdblue added a commit to rdblue/parquet-mr that referenced this pull request Jan 6, 2017
This removes the check added in PARQUET-278 that rejects schema groups
that have no fields. Selecting 0 columns from a file is allowed and used
by Hive and SparkSQL to implement queries like `select count(1) ...`

Author: Ryan Blue <blue@apache.org>

Closes apache#263 from rdblue/PARQUET-363-allow-empty-groups and squashes the following commits:

ab370f1 [Ryan Blue] PARQUET-363: Update Type builder tests to allow empty groups.
926932b [Ryan Blue] PARQUET-363: Add write-side schema validation.
365f30d [Ryan Blue] PARQUET-363: Allow empty schema groups.
WenboZhao pushed a commit to twosigma/parquet-mr that referenced this pull request Mar 15, 2018
This removes the check added in PARQUET-278 that rejects schema groups
that have no fields. Selecting 0 columns from a file is allowed and used
by Hive and SparkSQL to implement queries like `select count(1) ...`

Author: Ryan Blue <blue@apache.org>

Closes apache#263 from rdblue/PARQUET-363-allow-empty-groups and squashes the following commits:

ab370f1 [Ryan Blue] PARQUET-363: Update Type builder tests to allow empty groups.
926932b [Ryan Blue] PARQUET-363: Add write-side schema validation.
365f30d [Ryan Blue] PARQUET-363: Allow empty schema groups.
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

Successfully merging this pull request may close these issues.

4 participants