Skip to content

Commit

Permalink
convert datetime field values to utf
Browse files Browse the repository at this point in the history
  • Loading branch information
kreeben committed Jul 3, 2017
1 parent eb0e946 commit 047eb76
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ResinCore/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@ public Field(string key, object value, bool store = true, bool analyze = true, b
Analyze = analyze;
Index = index;

object obj = value;

This comment has been minimized.

Copy link
@mdissel

mdissel Jul 3, 2017

What about nullable types?
DateTime? , long?

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

That's not exactly scope screep, but it is domain creep. You should rinse your documents of any null fields before sending them to the database, is my opinion.

It's surely also a matter of how you look at things. I cannot think of a scenario where I before I send my data (i.e. documents) to the database I couldn't parse a null field as "this data is not part of the document". A feature in a document database that is missing from a relational, table-based database is that with a document DB you can store everything in one table where each row has variable number of columns and each column is of variable length. I say: don't populate your documents with data you do not want to store or index.

This comment has been minimized.

Copy link
@mdissel

mdissel Jul 3, 2017

But what if you want to search for "each person with no birthdate set"?

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

I'm currently working on the ResinDB query language (ResQL). Right now the QL is a (ugly) cousin of the Lucene query syntax.

In SQL you would express your query as:

select * from person where birthday is null

In Elasticssearch:

!(exists:birthday)

I'm not sure how to express that in ResQL (yet). But once I figure that out, filtering on nullable fields (i.e. fields that is not part of the document at all) will be implemented.

Perhaps something in the likes of:

birthday:null

(where "null" would be a reserved word you could never ever use as real data).

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

Maybe:

birthday:\0

This comment has been minimized.

Copy link
@mdissel

mdissel Jul 3, 2017

Using an existing (feature complete) syntax has an advantage above creating your own..

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

I agree, but implementing either SQL or graphQL is so tedious. I would be awsome, but I shall have to grab some funding before even considering such a quest.

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

Anyway, adding support for nullable fields to tha API is not such a grand quest. It could go into the query language later on.

This comment has been minimized.

Copy link
@mdissel

mdissel Jul 3, 2017

From a service perspective I think the enige should support three values:

  • not defined (property does not exists in document)
  • defined but empty
  • defined with value

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

Thx, I'll consider that.


if (value is DateTime)
{
_value = ((DateTime)value).Ticks.ToString();
obj = ((DateTime)value).ToUniversalTime().Ticks.ToString();
}
else if (value is string)

if (obj is string)
{
_value = value.ToString();
_value = obj.ToString();
}
else
{
// Assumes all values that are not DateTime or string must be Int32.
// Assumes all values that are not DateTime or string must be Int64.

This comment has been minimized.

Copy link
@mdissel

mdissel Jul 3, 2017

But what about numeric values with decimals?

This comment has been minimized.

Copy link
@kreeben

kreeben Jul 3, 2017

Author Owner

Did you notice the TODO that comes right after that row? ;)

As of right now, ResinDB supports strings, dates, integers as well as decimal data that can be transformed into integer data by means of scaling.


// TODO: implement native number indexes

var len = int.MaxValue.ToString().Length;
_value = value.ToString().PadLeft(len, '0');
var len = long.MaxValue.ToString().Length;
_value = obj.ToString().PadLeft(len, '0');
}
}
}
Expand Down

0 comments on commit 047eb76

Please sign in to comment.