How to create multiple head rows on a table with asciidoctor - pdf

I'm using asciidoctor v2.0.17 and try to create a table with multiple rows in a header like
+----------+-----------------------------------------+
|Value |Name |
| +-----------------------------------------+
| |Description |
+----------+-----------------------------------------+
| first part of a long table (more than obe page) |
| .... |
+----------+-----------------------------------------+
<new page>
+----------+-----------------------------------------+
|Value |Name |
| +-----------------------------------------+
| |Description |
+----------+-----------------------------------------+
| next part of a long table (more than obe page) |
| .... |
+----------+-----------------------------------------+
in a pdf-document. Because this feature was been added to asciidoctor two years ago I've tried it with
[%header,hrows=2,cols="1,9",width="100%"]
|====================
.2+h| Value
h| Name
h| Description
| ...
| ...
...
|====================
But this fails:
The header contains the first line only after a pagebreak
the vertical span was been ignored
so the result looks like
+----------+-----------------------------------------+
|Value |Name |
|----------+-----------------------------------------+
|Descriptio|
|n |
+----------+-----------------------------------------+
| first part of a long table (more than obe page) |
| .... |
+----------+-----------------------------------------+
<new page>
+----------+-----------------------------------------+
|Value |Name |
+----------+-----------------------------------------+
| next part of a long table (more than obe page) |
| .... |
+----------+-----------------------------------------+
Because the changes done of the issue #1539 are contained in the used version of asciidoctor I assume that I have the right version. Has some one any idea how I can sove the problem?
Best reards,
Ralf Ebert

It seems that this feature was been deactivated by the developers. It is possible to activate this feature by activating the commented-out part in the deleted file:
ruby/lib/ruby/gems/3.1.0/gems/asciidoctor-pdf-1.6.2/lib/asciidoctor/pdf/converter.rb
(Lines 1921-1925 in version 2.0.17 of asciidoctor)
But it won't work with vertical span.

Related

SQL table transformation. How to pivot a certain table?

How would I do the pivot below?
I have a table like this:
+------+---+----+
| round| id| kpi|
+------+---+----+
| 0 | 1 | 0.1|
| 1 | 1 | 0.2|
| 0 | 2 | 0.5|
| 1 | 2 | 0.4|
+------+---+----+
I want to convert the id column into multiple columns (same amount of different ids), with KPI value as their values and in the new table we keep the rounds like in the first table.
+------+----+----+
| round| id1| id2|
+------+----+----+
| 0 | 0.1| 0.5|
| 1 | 0.2| 0.4|
+------+----+----+
Is it possible to do this in SQL? How to do that?
You are looking for a pivot function. You can find details on how to do this here and here. The first link also provides input into how to do this if you have an unknown number of columnnames.

How to define a relationship between two tables from different sources with different identifiers

Background:
I'm working on a project that does not allow me to share the data, but I'll do my best to give you some visualisation below. So before going further, I know (some) SQL, and I have done basic work relationship before, but the data was clean and simple and for some reason I just can't' figure out a solution.
Problem (?)
I'm trying to define a relationship between two tables from two different sources that each work with different identifiers. I do have however a mapping table from one of those but again the identifiers do not align. Let me try explain visually:
| TABLE 1 (cies) | | TABLE 2 (forms) |
| ------------ | | ------------- |
| id(PK) | | id(PK) |
| 4_digit_code | | 16_digit_code |
| ...more fields | | ...more fields |
The second source provided me a mapping table they use internally:
| MAPPING TABLE |
| ------------- |
| id(PK) |
| 4_digit_code | (= to the one in TABLE 1)
| 16_digit_code | (= to the one in TABLE 2)
My first thought was to create a script and just merge the info in the mapping table in TABLE 1 like so:
| TABLE 1 | | TABLE 2 |
| ------------ | | ------------- |
| id(PK) | | id(PK) |
| 16_digit_code | ==== | 16_digit_code |
| 4_digit_code |
The issue here is the 16_digit_code is not unique so I believe this does not work. Now comes something I have no experience with so I am just thinking out loud here:
Can I keep (?) the mapping table and each time reference that one to get my data from the other table via another? On other hand should not all values in a mapping table be unique as well for it to work? The reason there are non-unique values is that (some) very old numbers end up getting recycled.
For example get me all forms from company with id 1:
| TABLE 1 | | MAPPING TABLE | | TABLE 2 |
| ------------ | | ------------- | | ------------- |
| id(PK) | | id(PK) | | id(PK) |
| 16_digit_code | | 16_digit_code | ==== | 16_digit_code |
| 4_digit_code | ==== | 4_digit_code | | ...more fields |
And in the above, I would not know how to efficiently approach this problem. I really don't know if it makes any sense though what I am saying or I am missing something or making this way too complex.
Solution?
I'd love it if someone could point me in the right direction. And if you have the solution I'd love to know the reasoning, not just the solution as I'd love to learn from this for the future obviously.
Edit/Clarification:
Just for completion sake, the mapping combination (4 digit + 16 digit code) is unique. Although, as I said earlier one 16 digit code can be linked to multiple 4 digit codes.

How to import Excel table with double headers into oracle database

I have this excel table I am trying to transfer over to an oracle database. The thing is that the table has headers that overlap and I'm not sure if there is a way to import this nicely into an Oracle Database.
+-----+-----------+-----------+
| | 2018-01-01| 2018-01-02|
|Item +-----+-----+-----+-----+
| | RMB | USD | RMB | USD |
+-----+-----+-----+-----+-----+
| | | | | |
+-----+-----+-----+-----+-----+
| | | | | |
+-----+-----+-----+-----+-----+
| | | | | |
+-----+-----+-----+-----+-----+
| | | | | |
+-----+-----+-----+-----+-----+
The top headers are just the dates for the month and then their respective data for that date. Is there a way to nicely transfer this to an oracle table?
EDIT: Date field is an actual date such as 02/19/2018.
If you pre-create a table (as I do), then you can start loading from the 3rd line (i.e. skip the first two), putting every Excel column into the appropriate Oracle table column.
Alternatively (& obviously), rename column headers so that file wouldn't have two header levels).

modelling hierarchical data warehouse dimension

I'm trying to model a dimension that is hierarchical and has an indeterminate amount of features at each level. Here's an example on how the tables are structured in the data source
+-------------+ +-------------+ +-------------+
|Product +--------------+SubCategory +----------------+Category |
+------+------+ +------+------+ +-------+-----+
| | |
| | |
+------+----------+ +-------+-------------+ +-------+----------+
|Product Features | |SubCategory Features | |Category Features |
+-----------------+ +---------------------+ +------------------+
There's a one to many relationship from Product -> SubCategory and from SubCategory -> Category. Each of the Product/SubCategory/Category also reference their respective features table. The number of features is however not fixed and could be 0.
The fact tables I'm trying to build needs to be at the level of product for its grain, and without the features I could just make a dimension with each of these as columns like so:
+-----------------+
|Dim_Product |
+-----------------+
|Dim_Product_Id |
|Product |
|SubCategory |
|Category |
|... |
+-----------------+
But then all the features would be lost.
Is it possible to keep the dimension at the product level and keep all the features from each hierarchy? Or would it be necessary to make a bridge table containing all the combinations of all the features in the hierarchies? Would I need to break the levels out into their own dimension (i.e. Dim_Product, Dim_SubCategory, Dim_Category) instead? There is also fixed attributes for each heirarchy level, so can these be just flattened out and included as columns if a single dimension is a suitable option?
It seems tricky, since you don't know exactly the number of features, this is my suggestion, though the bridge table would be quite big.
+-----------------+
|Dim_Product |
+-----------------+
|Dim_Product_Id |
|Product |
|SubCategory |
|Category |
|... |
+-----------------+
|
|
+-----------------+
|BridgeTable |
+-----------------+
|Dim_Product_Id |
|Feature_Id |
+-----------------+
|
|
+-----------------+
|Features |
+-----------------+
|Feature_Id |
|FeatureDescription
|TypeOfFeature |
+-----------------+
with TypeOfFeature being one of (ProductFeature, SubCategory, Category).

unique constraint (w/o Trigger) on "one-to-many" relation

To illustrate the problem, I make an example:
A tag_bundle consists of one or more than one tags.
A unique tag combination can map to a unique tag_bundle, vice versa.
tag_bundle tag tag_bundle_relation
+---------------+ +--------+ +---------------+--------+
| tag_bundle_id | | tag_id | | tag_bundle_id | tag_id |
+---------------+ +--------+ +---------------+--------+
| 1 | | 100 | | 1 | 100 |
+---------------+ +--------+ +---------------+--------+
| 2 | | 101 | | 1 | 101 |
+---------------+ +--------+ +---------------+--------+
| 102 | | 2 | 101 |
+--------+ +---------------+--------+
| 2 | 102 |
+---------------+--------+
There can't be another tag_bundle having exactly the same combination from tag 100 and tag 101.
There can't be another tag_bundle having exactly the same combination from tag 101 and tag 102.
How can I ensure such unique constraint when executing SQL "concurrently"!!
that is, to prevent concurrently adding two bundles with exactly the same tag combination
Adding a simple unique constraint on any table does not work,
Is there any solution other than Trigger or explicit lock.
I come to only this simple way: make tag combination into string, and let it be a unique column.
tag_bundle (unique on tags) tag tag_bundle_relation
+---------------+-----------+ +--------+ +---------------+--------+
| tag_bundle_id | tags | | tag_id | | tag_bundle_id | tag_id |
+---------------+-----------+ +--------+ +---------------+--------+
| 1 | "100,101" | | 101 | | 1 | 101 |
+---------------+-----------+ +--------+ +---------------+--------+
| 100 | | 1 | 100 |
+--------+ +---------------+--------+
but it seems not a good way :(
Why the constraint of 'without a trigger'? With it, combined with a bit of data duplication, you can get what you need. Change your 'tags' field in your solution to an array field of INTEGERs (or whatever type tag_id is)
While recognising the unpleasantness of the solution, I don't see a way round it. Though I would use an array instead of a string for 'tags', put it in a separate table from tag_bundle, still make it unique and put a trigger on tag_bundle_relation to update the tags field with array_agg(tag_id) (>8.4), and if that fails, fail the trigger update.
In order to work correctly when multiple transactions will be updating the tables, you will need to create a deferable, initially deferred, constraint trigger.