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

Kite errors out when quoted csv header contains space #433

Open
dipeshtech opened this issue Feb 2, 2016 · 2 comments
Open

Kite errors out when quoted csv header contains space #433

dipeshtech opened this issue Feb 2, 2016 · 2 comments

Comments

@dipeshtech
Copy link

I tried kite sdk to create avro schema out of csv file using below command:
kite-dataset csv-schema test.CSV --class Sample

It fails (when column header has spaces):
"field 1","field 2","field 3"
"Agwam","Agwam, MA","25007"

with following error:

Unknown error: Bad header for field, should start with a character or _ and can contain only alphanumerics and _ 0: "field 1"

Success example:
"field1","field2","field3"
"Agwam","Agwam, MA","25007"

Not sure if there is a way to handle it.

@yawaramin
Copy link

So, it looks like this is because Avro requires field names to obey the above specs. See https://github.com/kite-sdk/kite/blob/release-1.1.0/kite-data/kite-data-core/src/main/java/org/kitesdk/data/spi/filesystem/CSVUtil.java#L179 for the exact code where this is happening.

If the field name doesn't match the specs, it's impossible to generate an Avro schema using that name. So this is a case of that more general issue. We can call this something like 'Kite CSV schema inference errors when headers don't obey Avro specs'.

One solution would be to slightly change the inferSchema and inferNullableSchema methods that currently take the Set<String> requiredFields parameter. We could make this Map<String, String> requiredFieldMappings to let the user specify Avro-safe names for all the required fields. Then inferSchemaInternal uses the mappings to generate the schema.

@sshikov
Copy link

sshikov commented Jan 19, 2018

We are often have files with just text in the header row, containing spaces, cyrillic letters etc, so field names inferred also doesn't match Avro's specification.

Our team proposal is to do some automatic transformation on such field names, like base32 encoding, plus generate schema doc using original column value.

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

3 participants