I am trying to print the results in ASCII tables as below
------------------------------------------------------
originalEventTimestamp | text
------------------------------------------------------
2020-07-25 19:09:36.0604182 | abcd
2020-07-25 19:09:36.0570676 | abcd
2020-07-25 19:09:36.0505681 | abcd
2020-07-25 19:09:36.0454867 | abcd
Noticed kql_raw_result has the following methods, but non of them print in the above format:
Kqlmagic.results.ResultSet
_kql_raw_result_.__str__
_kql_raw_result_.raw_json
_kql_raw_result_.to_csv
I would use to_dataframe() and then you can print it easily
Related
I have a column in which each cell contains data in this format:
ABC | DEF | GHI | |
ABC | DEF | GHI | JKL |
ABC | DEF | | |
I need to extract the first and last valid (i.e. not empty) sub-strings.
I can extract the first/last substring easily enough using a formula (though it's clunky):
FIRST SUBSTRING
=TRIM(MID(SUBSTITUTE(A1,"|",REPT(" ",LEN(A1))),(4-4)*LEN(A1)+1,LEN(A1)))
LAST SUBSTRING
=TRIM(MID(SUBSTITUTE(A1,"|",REPT(" ",LEN(A1))),(4-1)*LEN(A1)+1,LEN(A1)))
This basically uses SUBSTITUE to replace the "|" delim with spaces, then uses MID to the extract the nth substring followed by TRIM to replace the extra spaces... but if the last delimited substring is empty it returns an empty string (as its meant to i guess).
How can I modify this formula to extract the last valid substring (i.e. not empty " "). Could someone please show me how to do this using VBA code ?
ABC | DEF | GHI | |
Output column 1: ABC
Output column 2: GHI
ABC | DEF | GHI | JKL |
Output column 1: ABC
Output column 2: JKL
ABC | DEF | | |
Output column 1: ABC
Output column 2: DEF
let's say your worksheet is WS
and your values starts at cell A2 till A120
dim zeValue$, out1$, out2$
dim i as int
for i = 2 to 120
zeValue = replace(replace(WS.range("A" & i),' ',''),'|','')
out1 = left$(zeValue,3)
out2 = right$(WS.range(zeValue, 3)
debug.print('out1 : '+out1)
debug.print('out2 : '+out2)
next i
Not tested but that should work
Good luck pal !
I have a file with 10,1900 lines with Delimiter as 5 ('|') [obviously 6 columns now] , and I have statement in sixth column like "Dropped 12 (0.01%)" !! I am longing to extract the number after Dropped within brackets;
Actual -- Dropped 12 (0.01%)
Expected -- 0.01
I need a solution using Apache pig.
You are looking for the REGEX_EXTRACT function.
Let's say you have a table A that looks like:
+--------------------+
| col1 |
+--------------------+
| Dropped 12 (0.01%) |
| Dropped 24 (0.02%) |
+--------------------+
You can extract the number in parenthesis with the following:
B = FOREACH A GENERATE REGEX_EXTRACT(col6, '.*\\((.*)%\\)', 1);
+---------+
| percent |
+---------+
| 0.01 |
| 0.02 |
+---------+
I'm specifying a regex capture group for whatever characters are between ( and %). Notice that I'm using \\ as the escape character so that I match the opening and closing parenthesis.
I have data of the form
-----------------------------|
6031566779420 | 25 | 163698 |
6031566779420 | 50 | 98862 |
6031566779420 | 75 | 70326 |
6031566779420 | 95 | 51156 |
6031566779420 | 100 | 43788 |
6036994077620 | 25 | 41002 |
6036994077620 | 50 | 21666 |
6036994077620 | 75 | 14604 |
6036994077620 | 95 | 11184 |
6036994077620 | 100 | 10506 |
------------------------------
and would like to create a dynamic number of new columns by treating each series of (25, 50, 75, 95, 100) and corresponding values as a new series. What I'm looking for as target output is,
--------------------------
| 25 | 163698 | 41002 |
| 50 | 98862 | 21666 |
| 75 | 70326 | 14604 |
| 95 | 51156 | 11184 |
| 100 | 43788 | 10506 |
--------------------------
I'm not sure what the name of the sql / postgres operation I want is called nor how to achieve it. In this case the data has 2 new columns but I'm trying to formulate a solution that has has many new columns as are groups of data in the output of the original query.
[Edit]
Thanks for the references to array_agg, that looks like it would be helpful! I should've mentioned this earlier but I'm using Redshift which reports this version of Postgres:
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.1007
and it does not seem to support this function yet.
ERROR: function array_agg(numeric) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
Query failed
PostgreSQL said: function array_agg(numeric) does not exist
Hint: No function matches the given name and argument types. You may need to add explicit type casts.
Is crosstab the type of transformation I should be looking at? Or something else? Thanks again.
I've used array_agg() here
select idx,array_agg(val)
from t
group by idx
This will produce result like below:
idx array_agg
--- --------------
25 {163698,41002}
50 {98862,21666}
75 {70326,14604}
95 {11184,51156}
100 {43788,10506}
As you can see the second column is an array of two values(column idx) that corresponding to column idx
The following select queries will give you result with two separate column
Method : 1
SELECT idx
,col [1] col1 --First value in the array
,col [2] col2 --Second vlaue in the array
FROM (
SELECT idx
,array_agg(val) col
FROM t
GROUP BY idx
) s
Method : 2
SELECT idx
,(array_agg(val)) [1] col1 --First value in the array
,(array_agg(val)) [2] col2 --Second vlaue in the array
FROM t
GROUP BY idx
Result:
idx col1 col2
--- ------ -----
25 163698 41002
50 98862 21666
75 70326 14604
95 11184 51156
100 43788 10506
You can use array_agg function. Asuming, your columns are named A,B,C:
SELECT B, array_agg(C)
FROM table_name
GROUP BY B
Will get you output in array form. This is as close as you can get to variable columns in a simple query. If you really need variable columns, consider defining a PL/pgSQL procedure to convert array into columns.
I've got a table in my database that I would like to export in different files depending on a specific name (let say scientific_name - example below). For each scientific name in my table I would like to:
create the corresponding file, e.g. ab.txt, ac.txt
insert in this file all the corresponding values.
Examples
For ab.txt:
id, value
1, 2
3, 3
for ac.txt:
id, value
2, 5
4, 4
Example of my table:
id | scientific_name | Name | value
1 | ab | aa | 2
2 | ac | cc | 5
3 | ab | aa | 3
4 | ac | cc | 4
Do you have any idea how I could do that?
Thanks a lot
Arnaud
The text file output step has an option that allows you to specify a field in the dataset that has the name of the file that's going to be created.
Look at this example:
https://drive.google.com/file/d/0BwwXJ3GUloGURUJqT0RkT3g0SmM/view?usp=sharing
It creates 2 different files depending on the name of the column in the dataset. It's pretty simple, but it shows the functionality you need. Bear in mind, this transformation will output the files directly on kettle's installation folder.
I am making a report in SSRS. Database contains table "Project" with a "Notes" field which is formated by users in this way:
#Completed
-line 1 description
-line 2 description
-line3 and so on
#Planned
-line 1 etc.
#Risks
- line1 ...etc
There are always only those 3 categories and in that order. Bullet points can be from 0 to unlimited (but i never seen more than 10)
I would like to get output(dataset) in format (so I can group them in tablix):
ProjectID, Maincategory, itemID, subcategories.
For example
1 | Completed | 1 | line1
1 | Completed | 2 | line2
1 | Completed | 3 | line3
...
1 | Planned | 1 | Line1
...
1 | Risks | 1 | line1
...
I cant change source DB so I cant create stored procedure, it should be regular query.
I looked at various solutions with CTE recursions but I just cant figure out how they work in oreder to change them for my case.
Thank you!