Given this from InputRoot in ESQL (Split Esql) - ibm-integration-bus

<xml>*** 1| 2| 3| 4| 5| 6| 7**<xml>
I'd like to create this in my OutputRoot:
<xml> <a>1</a> <b>2</b> <c>3</c> <d>4</d> <e>5</e> <f>6</f> <g>7</g> </xml>

Two approaches to this,
Tactical Solution: use ESQL TRANSLATE() to replace the required characters
https://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05261_.htm
Strategic Solution: If this is a regular requirement create message models using DFDL then you can just switch or map between the two formats as required.
https://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/bd40450_.htm

Related

Relational algebra, Find unique Names

Say I have the following relational schema:
+-------+------------+
| Name | Subject |
+--------------------+
| 1 | A |
| 1 | B |
| 1 | C |
| 2 | D |
| 2 | E |
| 3 | F |
| 4 | G |
| 5 | H |
| 5 | I |
+-------+------------+
and I seek these tuples:
3
4
How to get unique names for people only doing 1 subject?
Here's an example based on what AntC described:
NS={
name:string, subject:string
'1' , 'A'
'1' , 'B'
'1' , 'C'
'2' , 'D'
'2' , 'E'
'3' , 'F'
'4' , 'G'
'5' , 'H'
'5' , 'I'
}
(π name NS) - π name (σ s!=subject ((ρ s←subject NS) ⨝ NS))
If you want to test this out you can try it at:
https://dbis-uibk.github.io/relax/calc.htm
Choc Boo, welcome to stackoverflow [relational-algebra]. I strongly suggest you find yourself a textbook or online learning resource that will take you step-by-step -- preferably something you can share with other learners.
Are you sure it's RA you want to learn? Or SQL? They're very different: as a noob, learning one will probably completely confuse you wrt the other. (The connection between them won't become clear until you're much deeper in.)
There are places you can run RA online. But beware they use a specific dialect of RA, which might not be the one you're trying to learn.
Your query could perhaps be expressed as:
"Return all Names that appear in a single tuple."
Note I didn't mention "only doing 1 subject": a relation is a set; if any Name appears more than once it must be that it appears with multiple Subjects.
There's a 'quick and dirty' way to an answer: for each Name count how many tuples; restrict the result to return only those with count == 1. (That way will need using an advanced RA operator for counting.)
There's a longer-winded way that uses only more primitive operators: take two versions of your relation; pair each tuple with each from the other version; the Names that appear in more than one tuple will pair up in multiple ways same-Name-different-Subject; those are the Names you don't want.
What do I mean by "two versions"? Find out about the Rename operation (ρ). What do I mean by "pair ... with ..."? Find out about the Join operation (⋈). What do I mean by "don't want"? Find out about the set difference operator (-): I said relations are sets.

DFS algorithm vs Parent-child in tree category

I need to implement a category tree like this:
laguages
.... Web
........ PHP
........ Python
........ HTML
.... System
........ C
........ C++
........ GO
........ RUST
So I have a table like this:
id | title | parent_id
1 | system| 0
2 | c | 1
3 | c++ | 1
4 | rust | 1
5 | web | 0
6 | php | 5
7 | python| 5
8 | html | 5
If i want to implement tree structure I have two solutions.
using a recursive function and create a parent-child array
using
DFS search to make this structure that I need to add left and
right column in the database table.
So my question is: what is deferences between this two solutions? and which one is better?
If the search operations will be more frequent, I would suggest array based approach because of the advantage of random access. In tree based structures, the search operations tend to be O(height) costly and the best height for balanced trees is O(log n).
On the contrary if update operations are more frequent, then I would go for Tree-based approach, since insertion and deletion is not very efficient in arrays due to shifting of elements involved.
Custom Approach
My Approach would have been the adjacency list data structure if, your child arrays Web or System are reasonably small. One could access the list for Web or System in constant time O(1) . Coming to deletion linked lists overcome arrays in case of insertion and deletions, and since the lists are not that long, search wont cause that much of problem time-wise.
I think if the three structure isn't more than what you described (2 levels) and not n levels isn't a right question but one of things you should have in mind.
in php =script language we do it much simple(the case of 2 levels) :
<?php
$source=Array(' system',Array(' php ',' c++ ',' html '),' web ',Array(' c ',' rust ',' python'));
function br(){echo('<br>');}
function printr($ar){
if(is_array($ar)){
foreach($ar as $key){
print(' |____'.$key);
br();
}
}else{
print('['.$ar.']');br();
}
return true;
}
array_map("printr", $source);
?>
the output:
[ system]
|____ php
|____ c++
|____ html
[ web ]
|____ c
|____ rust
|____ python
this array :
$source=Array(
' system',
Array(' php ',' c++ ',' html '),
' web ',
Array(' c ',' rust ',' python')
);
you should obtain it with a "generator" input from a form ,from a internal file created with another generator (web,compiler any kind)...
the maximum results comes when perfect input optimizations is stored in a intelligent structure can avoid use of LOTS CALCULATIONS ,Iterations( DFS algorithm or Parent-child or any OTHER method)
/*
Also using of serialize
functions you can store an entirely array,
unserialize will help you to restore your array
*/
$source=unserialize($from_a_table_1_row_forever);
// $from_a_table_1_row_forever=obtained from some your function to read it from a database,file ...etc
//now is good to use in memory,i mean that multi array
//when you want to store changes in some generator:
$for_a_table_1_row_forever=serialize($source);
good_to_write_it_in_a_single_table_row($for_a_table_1_row_forever);
// (some your function to write in a database,file ...etc)

CockroachDB: select and cast byte -> string type

I've got a query storing a UUIDv4 as a byte type in CockroachDB (v1.0). Its generated with Cockroach's documented 'uuid_v4()' function. When making selections, the results will return with the byte-typed format, like so:
"\x9d\xce`\xb3p\x9aKB\xbe\xba\xeb\xec~\x9e\xfb\x93"
while the goal is to have it output a string uuidv4, like:
"abcd-12345-asdifoekc"
I've read the casting docs on: https://www.cockroachlabs.com/docs/data-types.html#data-type-conversions--casts but still cannot figure out how to do this conversion during a SELECT statement.
Use the from_uuid() builtin, as follows:
root#:26257/> SELECT from_uuid(uuid_v4());
+--------------------------------------+
| from_uuid(uuid_v4()) |
+--------------------------------------+
| 4817bb15-4d93-4b77-b7d1-1e5cfb8360e3 |
+--------------------------------------+
(1 row)

The difference between 2 negative numbers gives negative result instead of positive [SSRS]

Using SQL Server 2014, I have SSRS report with matrix inside.
Problem: difference between 2 negative numbers doesn't give sum
The expression of field is:
= ReportItems!Textbox1.value - ReportItems!Textbox2.value
In report it looks like:
Textbox1 | Textbox2 | Expression result |
------------------------------------------
-73 | -170 | -97 |
So i have result -97 instead of 97.
How I can fix this problem?
that is weird i tied table, matrix and text boxes all seem to work fine. i'm using ssrs 2012 though.
you could try something like
=(ReportItems!Textbox1.Value - ReportItems!Textbox2.Value) * iif( ReportItems!Textbox1.Value > ReportItems!Textbox2.Value,1,-1)

Group and Count an Array of Structs

Ruby noob here!
I have an array of structs that look like this
Token = Struct.new(:token, :ordinal)
So an array of these would look like this, in tabular form:
Token | Ordinal
---------------
C | 2
CC | 3
C | 5
And I want to group by the "token" (i.e. the left hand column) of the struct and get a count, but also preserve the "ordinal" element. So the above would look like this
Token | Merged Ordinal | Count
------------------------------
C | 2, 5 | 2
CC | 3 | 1
Notice that the last column is a count of the grouped tokens and the middle column merges the "ordinal". The first column ("Token") can contain a variable number of characters, and I want to group on these.
I have tried various methods, using group_by (I can get the count, but not the middle column), inject, iterating (does not seem very functional) but I just can't get it right, partly because I don't have a good grasp of Ruby and the available operations / functions.
I have also had a good look around SO, but I am not getting very far.
Any help, pointers would be much appreciated!
Use Enumerable#group_by to do the grouping for you and use the resulting hash to get what you want with map or similar.
structs.group_by(&:token).map do |token, with_same_token|
[token, with_same_token.map(&:ordinal), with_same_token.size]
end

Resources