Skip to content

Conversation

@knighton
Copy link
Contributor

This PR was split out of a larger Parquet streaming PR, to follow.

  1. Implement allow_schema_mismatch -- checks all shards to verify that their schema (column name and type signatures) match. This functionality is an important safety check for Parquet streaming relating to accidentally including Parquet files and other user error.
  2. We are able to do this across shard types (a string field in a JSONL shard should be returned the same as that same string field in an MDS shard, say) because we now have the concept of logical (as opposed to physical) column types. Logical column types are Streaming's vocabulary of types which are shared by all shard formats, which each shard's encodings map to. Shard formats (really, talking about MDS here) may have multiple ways to encode a value, that all have the same logical type.

Copy link
Contributor

@karan6181 karan6181 left a comment

Choose a reason for hiding this comment

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

Looks good overall. Can you please add unit test for the new changes?

self.stream_per_shard = np.array(stream_per_shard, np.int64)
self.num_shards = len(self.shards)

# Maybe check all schemas match.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why the word maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the check may happen or it may not

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but it depends on whether the flag allow_schema_mismatch is true or not. So, maybe, check all schemas match?

class Str(Encoding):
"""Store str."""

logical_type = LogicalStr
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering, where is this getting used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

streaming.format.mds.encoding.MDSEncoding.logical_type (start here)
-> streaming.format.base.type.Type (then go to the logical type class)
-> streaming.format.base.type.Type.get_signature (it has a stringify single column method)
-> streaming.format.base.shard.base.Shard.get_logical_type_signature (which is used by shard to stringify all columns for equality comparison)
-> streaming.dataset.StreamingDataset.__init__ (which is needed for allow_schema_mismatch impl)

Copy link
Collaborator

@XiaohanZhangCMU XiaohanZhangCMU left a comment

Choose a reason for hiding this comment

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

LGTM

if not allow_schema_mismatch:
sigs = [shard.get_logical_type_signature() for shard in self.shards]
sig2count = Counter(sigs)
if len(sig2count) != 1:
Copy link
Collaborator

@XiaohanZhangCMU XiaohanZhangCMU Feb 22, 2024

Choose a reason for hiding this comment

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

Are mixed logical types of the same kind (like int32 + int64) not allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not allowed at this time for MVP. Maybe in the future, we would go with the wider type for all shards? But that would be kind of magical and might interact with custom getitem work?

Copy link
Contributor

@snarayan21 snarayan21 left a comment

Choose a reason for hiding this comment

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

Everything looks good to me! Could you add unit testing for these changes, including one that does fail the schema matching check?

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.

5 participants