[Herddb-dev] herddb-dev Digest, Vol 8, Issue 4

Enrico Olivelli eolivelli at gmail.com
Wed Feb 27 09:26:45 CET 2019


beside note: "[Herddb-dev] herddb-dev Digest, Vol 8, Issue 4" -> you
receiving "Digests" ? Maybe you can change your profile and receive
normal emails.

Apart from this, please create a pull request, it will be easier to
discuss and comment.

In the context of this change in that code block you have to add
ColumnTypes.NOTNULL_INTEGER
It is better to move that condition in a method in ColumnTypes like

public static boolean is validPrimaryKeyDataType(int dataType) {
   switch (dataType) {
        case STRING:
        case LONG:
        case INTEGER:
        case NOT_NULL:
         break;
       default :
      throw new ....
    }
}


Enrico

Il giorno mer 27 feb 2019 alle ore 09:22 Amit Chavan
<achavan1 at gmail.com> ha scritto:
>
> I have pushed bunch of changes for non null constraint onto a branch [https://github.com/amitvc/herddb/tree/support-non-null-constraints]
> While looking at Table.java line - 443 I see that the primary key type is checked as 4 different ColumnTypes. With me introducing non null types this code should be changed to check against non null. PK should not be nullable type.
> Current code -
>
> if (pk.type != ColumnTypes.STRING
>         && pk.type != ColumnTypes.LONG
>         && pk.type != ColumnTypes.INTEGER
>         && pk.type != ColumnTypes.TIMESTAMP) {
>     throw new IllegalArgumentException("primary key " + pkColumn + " must be a string or long or integer or timestamp");
> }
>
> Let me know what you think of the changes so far. I will add more unit tests.
>
> On Tue, Feb 26, 2019 at 7:58 PM Amit Chavan <achavan1 at gmail.com> wrote:
>>
>> Thanks, Enrico for such a quick and insightful response. I will be working on the patch tonight.
>>
>> On Tue, Feb 26, 2019 at 3:00 AM <herddb-dev-request at lists.herddb.org> wrote:
>>>
>>> Send herddb-dev mailing list submissions to
>>>         herddb-dev at lists.herddb.org
>>>
>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>         http://lists.herddb.org/mailman/listinfo/herddb-dev
>>> or, via email, send a message with subject or body 'help' to
>>>         herddb-dev-request at lists.herddb.org
>>>
>>> You can reach the person managing the list at
>>>         herddb-dev-owner at lists.herddb.org
>>>
>>> When replying, please edit your Subject line so it is more specific
>>> than "Re: Contents of herddb-dev digest..."
>>>
>>>
>>> Today's Topics:
>>>
>>>    1. Support not-null constraints (Amit Chavan)
>>>    2. Re: Support not-null constraints (Enrico Olivelli)
>>>
>>>
>>> ----------------------------------------------------------------------
>>>
>>> Message: 1
>>> Date: Mon, 25 Feb 2019 23:11:25 -0800
>>> From: Amit Chavan <achavan1 at gmail.com>
>>> To: herddb-dev at lists.herddb.org
>>> Subject: [Herddb-dev] Support not-null constraints
>>> Message-ID:
>>>         <CADsOBjMoMj2C-nGmDYVO+9BKGyAjta=9vHLLUFbzYs3-=E_ASQ at mail.gmail.com>
>>> Content-Type: text/plain; charset="utf-8"
>>>
>>> I am working on this ticket Issue-125
>>> <https://github.com/diennea/herddb/issues/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?
>>>
>>> 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.
>>>
>>> 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?
>>> -------------- next part --------------
>>> An HTML attachment was scrubbed...
>>> URL: <http://lists.herddb.org/pipermail/herddb-dev/attachments/20190225/5e511da3/attachment-0001.html>
>>>
>>> ------------------------------
>>>
>>> Message: 2
>>> Date: Tue, 26 Feb 2019 09:09:55 +0100
>>> From: Enrico Olivelli <eolivelli at gmail.com>
>>> To: Herddb developers <herddb-dev at lists.herddb.org>
>>> Subject: Re: [Herddb-dev] Support not-null constraints
>>> Message-ID:
>>>         <CACcefgen4obqqswfPVNUFVo4kQfOGQAYqqRbk4ZgSitg9mq+7w at mail.gmail.com>
>>> Content-Type: text/plain; charset="UTF-8"
>>>
>>> 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
>>>
>>>
>>> ------------------------------
>>>
>>> _______________________________________________
>>> herddb-dev mailing list
>>> herddb-dev at lists.herddb.org
>>> http://lists.herddb.org/mailman/listinfo/herddb-dev
>>>
>>>
>>> End of herddb-dev Digest, Vol 8, Issue 4
>>> ****************************************
>
> _______________________________________________
> 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