• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table Grid Structure And Query  RSS feed

 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm looking for a way to implement a table in memory to store data of primitive types (strings, integers, floats, etc), and would like to have a way to query data. I think using HashMap provides a good store (unless someone has a better idea), and there are 2 ways of doing this.

Assuming we have a row like this for the following example implementation.
Name, Sex, Rank, Dept, Age
Jane, Female, Manager, HR, 37

Implementation 1
In this case, we are using only one map object. We are going to store the primary key column as a key of the map, and the rest of the columns in a delimited fashion as value of the map.



Implementation 2
In this case, we are using a list of maps. We are going to store the columns of each row in a map, and then store this map in a list.



Questions
1) Which way of implementing this is better? And are there even better ways of doing this? There may be pros and cons with each approach and I'm happy to see what comments we have.
2) If I want to perform SQL like queries over this data? Is there a Java library that I can add and provides SQL syntax support? For example, the following should be possible but I haven't found such a library.


Thanks.

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this parsed data going to be inserted into database?

What does each row in the file represent? Say it's an employee. Creating a class called Employee will suffice.

Using a "map" just complicate things.

Most ORM library/framework like Hibernate, JPA, TopLink can query data and more. Which one to use depends on you considering ease of use, learning curve, installation and configuration etc.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map doesn't work like sql so you can use query into it.

Personally, I don't like both of the approach. Reasons are:

1) For the first approach, what if more than 1 Jane is available. As per map implementation values will be override in case of same key name.
2) For the second approach little bit better but you have to do lots of work to do to find information of any particular employee..

Are you able to think some other way, may be something unique between all the employee?
 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the comments. Persisting into database will be nice but it needs to be managed separately because I can't define at compile time a specific object type with known properties to represent the columns. It needs to allow me to load say any CSV source at runtime which structure is unknown beforehand.

I understand we can't query map like a database but I saw something available for Hazelcast and GridGain but the former doesn't do joins and the latter require you to know the object at compile time unless you buy the commercial version.

So basically you can imagine me trying to have something like Excel which allows you to import any arbitrary CSV except I want to query the data using SQL after the import.

I thought about using an embedded database but I prefer to avoid using one.

 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And sorry forgot to mention the code will handle non uniqueness of the data being import before trying to put it to the map.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!