[Herddb-dev] Support not-null constraints

Enrico Olivelli eolivelli at gmail.com
Tue Feb 26 09:09:55 CET 2019


Hello Amit,

Il giorno mar 26 feb 2019 alle ore 08:12 Amit Chavan
<achavan1 at gmail.com> ha scritto:
>
> I am working on this ticket Issue-125. Couple of questions -
> 1. Currently ColumnTypes in herddb are part of the ColumnTypes class. I am thinking of using an enum
> E.g
>
> public enum ColumnTypes {
>
>     NULLABLE_STRING(0, "nullable string"),
>     LONG(1, "long"),
>     INTEGER(2, "integer"),
>     NULLABLE_BYTEARRAY(3, "nullable bytearray"),
>     NULLABLE_TIMESTAMP(4, "nullable timestamp"),
>
>
> It breaks a lot of code which I am ok to fix. Want your opinion on this?

It is better to narrow down the patch to the minimum.
We can create an issue and work on the 'enum' change as a separate ticket.

>
> 2. Do we want to add support for null constraints on integers, longs and other data types. I have added support for string, byte array, timestamp.

Priorities:
- strings
- int
- long

then:
- timestamp

byte array is not really well supported yet

Anyway I think it is better to support all of them.

>
> 3. Once I make changes I want to test if we enforce the not null constraints in DDL queries. Any suggestions how to go about this?


First of all I suggest you to work at a lower level.
HerdDB SQL layer is built on top of the Key-Value low level layer.

Start from:
https://github.com/diennea/herddb/blob/master/herddb-core/src/test/java/herddb/core/CreateTableTest.java

This test case does not use SQL.
We can support SQL as a second task.
You can start checking  from CreateTableStatement.java and so
Table.java and so Column.java.
No change are needed if you are simply introducing new datatypes.

Let's start with an example, in order to keep the patch as small as
possible, let's not rename every data type, but just add a new
'INTEGER_NOTNULL"
You are going to find all of the usages of ColumnTypes.INTEGER and
there you will handle  ColumnTypes.INTEGER_NOTNULL at the same way as
ColumnTypes.INTEGER .

Probably the only function change you should introduce is in RecordSerializer
https://github.com/diennea/herddb/blob/82f81c30e036bf3575e676b55a5c019224a33ee8/herddb-core/src/main/java/herddb/codec/RecordSerializer.java#L283
https://github.com/diennea/herddb/blob/82f81c30e036bf3575e676b55a5c019224a33ee8/herddb-core/src/main/java/herddb/codec/RecordSerializer.java#L344

in those points you will have to fail (throw new
IllegalArgumentException by now, a subclass of
StatementExeceptionException in the future) if the object to be
serialized is NULL.

If you add a new case in CreateTableTest.java I expect to see a new
@Test method which creates a table with an INTEGER_NOTNULL field (non
in primary key) and it executes an INSERT, an UPDATE an assert that
the exeception is thrown


Recap:
- start with only a INTEGER_NOTNULL
- start creating a test, failing before your implementation
- do the implementation
- see the test passing
- add tests cases for other "interesting" code paths touched by your
change (like adding tests in RecordSerializer)


Great to see you on this list !
Cheers
Enrico









> _______________________________________________
> herddb-dev mailing list
> herddb-dev at lists.herddb.org
> http://lists.herddb.org/mailman/listinfo/herddb-dev


More information about the herddb-dev mailing list