Load data from 2 dim array into tabulator? - tabulator

Can I load a simple 2 dim array of text or number values into tabulator.
By a two dim array I mean an array of arrays all of the same length. All the examples seem to show an array of structures where each row has to contain the key (aka field or columnName). This seems a very wasteful amount of data when the keys or column names are the same in every row. The other spreadsheet librarys all seem to allow setting up a column model and supply data array values separately. Am I missing something?

Handling data in this way is fairly standard representational object model design paradigm that is used widely across a range of front end development scenarios.
These days it is a standard convention in most server side frameworks that when sending a data representation of a database model (or an array of them) to or from servers that it is sent as a JSON encoded object of that data. and it is particularly relevant when working with reactive data binding frameworks such as vue or react native which also bind display elements to the properties of these objects.
While it is not as efficient as a raw array of data, it means that object contains more contextual information, and it is the preferred standard in most simple front end data management situations, and they actually efficiency lost in all but the most intensive of compute requirement is negligible.
Tabulator is not primarily intended a spreadsheet library, it is designed for tabular representation of data which is very different, and most table based libraries do require data in the array of objects format.
If you want to import data your array format, you will need to implement a function to map your data into the expected array of objects format before passing it into the table.

new Tabulator('#table-id', {
data: [[1, 'A', true], [2, 'B', true], [3, 'C', false]],
columns: [{title: 'index', field: '0'}, {title: 'character', field: '1'},{title: 'bool', field: '2'}]
})
field - Required (not required in icon/button columns) this is the key for this column in the data array
The demo above work fine. If you know the columns of data, just set the column[i].field to the string(i).

Related

Dependent data validation list's with only two raw data columns

I have two columns whose data I want to input in a data validation list upon the selection of other validation list. And to do it, it's not suitable to have other auxiliar columns/tables other than the two mentioned ones. How would you approach it (see video illustration here)?
Thank in advance.😀

How to avoid dataset from renaming columns to value while mapping?

While mapping a dataset I keep having the problem that columns are being renamed from _1, _2 ect to value, value.
What is it which is causing the rename?
That's because map on Dataset causes that query is serialized and deserialized in Spark.
To Serialize it, Spark must now the Encoder. That's ewhy there is an object ExpressionEncoder with method apply. It's JavaDoc says:
A factory for constructing encoders that convert objects and primitives to and from the
internal row format using catalyst expressions and code generation. By default, the
expressions used to retrieve values from an input row when producing an object will be created as
follows:
- Classes will have their sub fields extracted by name using [[UnresolvedAttribute]] expressions
and [[UnresolvedExtractValue]] expressions.
- Tuples will have their subfields extracted by position using [[BoundReference]] expressions.
- Primitives will have their values extracted from the first ordinal with a schema that defaults
to the name `value`.
Please look at the last point. Your query is just mapped to primitives, so Catalyst uses name "value".
If you add .select('value.as("MyPropertyName")).as[CaseClass], the field names will be correct.
Types that will have column name "value":
Option(_)
Array
Collection types like Seq, Map
types like String, Timestamp, Date, BigDecimal

How do I output postgres node pg results as a table (array of arrays) rather than an array of hashes

I'm using node.js pg-promise module to access a postgres database. It's all working great, except that the results always come back as an array of rows, each of which is a json object with keys and values. It seems wasteful of bandwidth - more than half of the data goes to the keys on each field.
What I'm getting is an array of hashes:
[{
"ID":110744,
"Name":"Mann,Julie",
"Firstname":"Julie",
"Surname":"Mann",
"ShortName":null,
"Date":0,
"Email":"julie_simmo_68#xyz.com",
"Mobile":"0410038xxx",
"Phone":"42615xxx"
}
,{
}
,{}....]
What I want is an array of arrays:
[
[110744,"Mann,Julie","Julie","Mann",null,0,"julie_simm#xyz.com","0410038xxx","4261 5xxx"]
,
[...]
,
[...]
]
Is there any way to extract the data as an array of arrays? An array of rows, with each row being an ordered list of field values, in the same order as they appear in the SELECT statement. It will help with the speed of queries, and with unpacking the resulting data if they are just bare data in strict column order. I've been searching all day and can't find anything.
How to make pg-promise return rows as arrays?
I think this might be the solution, I'm just installing it now to see if it works.

Fastest (calculating) way to filter out a a portion of data from a big list of API data

I have a code that pulls data from an online JSON api. The data can be stored in variable array or in cells, I haven't decided yet but probably cells to save memory. (I have 24GB of memory, should I go for variables in order to have faster speed?)
The JSON as of now is <7MB. I don't know how big the parsed object would be (Using the VBA-JSON class). Each row of the data is leaded by a non-continuous ID#. Currently have 20K-30K rows.
Anyway, I have a few other sheets that would want a portion of the parsed data. They would be identified by ID. I know there's autofilter but I wonder if there's other faster options. Maybe get the row number by ID (MATCH?) and pull the other columns on that row?
As said other parts of the code can change like storing the parsed data in arrays or cells.

Handling the following use case in Cassandra?

I've been given the task of modelling a simple in Cassandra. Coming from an almost solely SQL background, though, I'm having a bit of trouble figuring it out.
Basically, we have a list of feeds that we're listening to that update periodically. This can be in RSS, JSON, ATOM, XML, etc (depending on the feed).
What we want to do is periodically check for new items in each feed, convert the data into a few formats (i.e. JSON and RSS) and store that in a Cassandra store.
So, in an RBDMS, the structure would be something akin to:
Feed:
feedId
name
URL
FeedItem:
feedItemId
feedId
title
json
rss
created_time
I'm confused as to how to model that data in Cassandra to facilitate simple things such as getting x amount of items for a specific feed in descending created order (which is probably the most common query).
I've heard of one strategy that mentions having a composite key storing, in this example, the the created_time as a time-based UUID with the feed item ID but I'm still a little confused.
For example, lets say I have a series of rows whose key is basically the feedId. Inside each row, I store a range of columns as mentioned above. The question is, where does the actual data go (i.e. JSON, RSS, title)? Would I have to store all the data for that 'record' as the column value?
I think I'm confusing wide rows and narrow (short?) rows as I like the idea of the composite key but I also want to store other data with each record and I'm not sure how to meld the two together...
You can store everything in one column family. However If the data for each FeedItem is very large, you can split the data for each FeedItem into another column family.
For example, you can have 1 column familyfor Feed, and the columns of that key are FeedItem ids, something like,
Feeds # column family
FeedId1 #key
time-stamp-1-feed-item-id1 #columns have no value, or values are enough info
time-stamp-2-feed-item-id2 #to show summary info in a results list
The Feeds column allows you to quickly get the last N items from a feed, but querying for the last N items of a Feed doesn't require fetching all the data for each FeedItem, either nothing is fetched, or just a summary.
Then you can use another column family to store the actual FeedItem data,
FeedItems # column family
feed-item-id1 # key
rss # 1 column for each field of a FeedItem
title #
...
Using CQL should be easier to understand to you as per your SQL background.
Cassandra (and NoSQL in general) is very fast and you don't have real benefits from using a related table for feeds, and anyway you will not be capable of doing JOINs. Obviously you can still create two tables if that's comfortable for you, but you will have to manage linking data inside your application code.
You can use something like:
CREATE TABLE FeedItem (
feedItemId ascii PRIMARY KEY,
feedId ascii,
feedName ascii,
feedURL ascii,
title ascii,
json ascii,
rss ascii,
created_time ascii );
Here I used ascii fields for everything. You can choose to use different data types for feedItemId or created_time, and available data types can be found here, and depending on which languages and client you are using it can be transparent or require some more work to make them works.
You may want to add some secondary indexes. For example, if you want to search for feeds items from a specific feedId, something like:
SELECT * FROM FeedItem where feedId = '123';
To create the index:
CREATE INDEX FeedItem_feedId ON FeedItem (feedId);
Sorting / Ordering, alas, it's not something easy in Cassandra. Maybe reading here and here can give you some clues where to start looking for, and also that's really depending on the cassandra version you're going to use.

Resources