3 Replies Latest reply on Jun 21, 2017 9:26 AM by carlesc RSS
    mnudel Explorer

    Overlapping datashape and inherent datatable fields

    In order to make "timestamp" inherent datashape field as a primary key, I created a data-shape with the same field set as a primary key. As a result, the datatable has got one "timestamp" field as a primary key. It solves my problem, but is it ok to do that? Can it cause any problems? Thanks.

      • Re: Overlapping datashape and inherent datatable fields
        carlesc Ninja

        Why don't you use a Stream instead of a DataTable, if PK it's timestamp, then it's time series data and Stream it's better suited than DataTables ( of course if you don't need Synchronous writes, on which case you are forced to use DataTables ).

         

        On the case that you need Synchronous writes, then you will need DataTables and on this case I would never add a column named timestamp ( neither location, sourceType, tags or source ) as thouse are already on any DataTable entry by default. If you want a column with a timestamp as pk, just name it different, it's totally ok ( but remember that you may have more than one entry at the same millisecond... on which case it invalidates it from using as PK ).

         

        Best Regards,.

          • Re: Overlapping datashape and inherent datatable fields
            mnudel Explorer

            Carles Coll, thank you for your response. The datatable supposed to save scaling values for different properties, users, things, etc. It must be editable by multiple users (adding, removing rows). The datatable seemed like a natural choice. But that comes with two challenges. First, whatever field I choose as a PK, I need to make sure that each new PK entry is unique. "userName + timestamp.toString()" could potentially solve it. Although slim, but there is a chance that the entry may be created at the same time (down to millisecond).

             

            My solution was to introduce a flag property which indicates when the datatable is use. If it is in use, a service can wait a random number (1-10) of milliseconds and try again. I'd be grateful if you could share your thoughts on that.