laurolins / nanocube

Eclipse Public License 1.0
731 stars 162 forks source link

Custom IDs for categorical indexing? #67

Closed latifuysal closed 5 years ago

latifuysal commented 5 years ago

Is there a way to supply a categorical value to number mapping so that given numbers are used as IDs instead of auto-generated numbers?

laurolins commented 5 years ago

You can define a list of "n" labels that will be mapped to the ID values of 0 to n-1 on the mapping file.

# mapping file example with pre-defined labels for two columns
# note that you should list all labels that appear at the corresponding input column
# if you want full control of which label matches to which ID.

values1=@
Amy
Ben
Claire
@;

# Amy -> 0
# Ben -> 1
# Claire -> 2

values2=@
Student
Professor
Athlete
@;

# Student -> 0
# Professor -> 1
# Athlete -> 2

index_dimension('value1', input(1), categorical(8,1,values1));
index_dimension('value2', input(2), categorical(8,1,values2));
measure_dimension('count',input(),u32);

You can also make the query retrieve the label instead of the id:

.b('value1',dive(1),'name)
latifuysal commented 5 years ago

Thanks for the quick response, and many thanks for this great project.