frictionlessdata / datapackage-java

A Java library for working with Frictionless Data Data Packages.
MIT License
20 stars 7 forks source link

Provide an API to interact with a data package descriptor #8

Closed georgeslabreche closed 6 years ago

georgeslabreche commented 6 years ago

Provide an API to interact with a data package descriptor.

georgeslabreche commented 6 years ago

@roll does this suffice?

public JSONArray getResources();
public JSONObject getResource(String resourceName);
public Object getProperty(String key);
public Object getPropertyString(String key);
public Object getPropertyJSONObject(String key);
public Object getPropertyJSONArray(String key);
roll commented 6 years ago

@georgeslabreche Will package.getResources() return an array of Resource instances?

Python/JavaScript API - https://github.com/frictionlessdata/implementations#datapackage (package.infer is kinda extra)

georgeslabreche commented 6 years ago

@roll: package.getResources() will return a JSONArray of JSONObjects representing Resource objects. This goes back to my first question in Issue #7. The reason I went ahead with JSONObjects and JSONArray is because its seems like 1) we don't necessarily want to map every single datapackage JSON elements to equivalent class and properties and 2) in the other libraries we are interacting with JSON structure directly so I thought I'd preserve that element. Nothing stops us from creating a Resource class and working with that, but where do we draw the lines as to what is represented by a class and what isn't?

If we want to proceed with creating Resource class, then I created a new issue for this, Issue #18, so that we may continue the conversation over there and close this particular issue.

roll commented 6 years ago

@georgeslabreche In other libs package.resources has Resource[] type. It's pretty common operation on data package when we iterate over resource and e.g. reading them:

for resource in package.resoures:
  print(resource.read(keyed=True))

So providing here API over raw data structures is very desirable.

And for raw data structure iteration users always could do:

for resource_descriptor in package.descriptor['resoures']:
  print(resource_descriptor)
georgeslabreche commented 6 years ago

@roll I agree. Will do! However, will close this GitHub Issue in particular and keep track of the work on Resource with Issue #18.