How to do an "in" expression with a previously defined/let externaldata - azure-data-explorer

Suppose I have a query like so:
SomeTable
| where Col1 !in (externaldata (something:string) [ #"https://...."])
However, if I have previously defined externaldata table in a let I cannot do this - syntax error:
let exttable=externaldata (something:string) [ #"https://...."])
Sometable
| where Col1 !in exttable

The arguments for the "in" operator must be enclosed in parenthesis for example:
let exttable=externaldata (something:string) [ #"https://...."])
Sometable
| where Col1 !in (exttable)
If you inline this expression then you will need double parenthesis such as:
Sometable
| where Col1 !in ((externaldata (something:string) [ #"https://...."]) ))

Related

KQL - Make the datasource variable

i have 2 datasources which i want to be variable based on condition. But i cannot call them using variables. im not sure how can i make this work
let T1 = TableMetric;
let T2 = TableImperial;
let T3 = othertable;
let tablemetrics = case(#uommetrics=="meter",T1,#uommetrics=="imperial",T2,T3);
tablemetrics
Semantic error: '' operator: Failed to resolve scalar expression named
'T1'. Query: 'let T1 = TableMetric; let T2 = TableImperial; let T3 =
othertable; let tablemetrics =
case('a'=="meter",T1,'a'=="imperial",T2,T3); tablemetrics
This logic can be implemented with union operator
.set TableMetric <| datatable(i:int)[1,2,3]
.set TableImperial <| datatable(i:int)[4,5,6]
.set othertable <| datatable(i:int)[7,8,9]
let uommetrics = "xxx";
union
(TableMetric | where uommetrics == "meter")
,(TableImperial | where uommetrics == "imperial")
,(othertable | where uommetrics !in ("meter", "imperial"))
i
7
8
9

Kusto Custom Sort Order?

How do I perform a custom sort order in Kusto?
Example query:
//==================================================//
// Assign variables
//==================================================//
let varStart = ago(2d);
let varEnd = now();
let varStorageAccount = 'stgacctname';
//==================================================//
// Filter table
//==================================================//
StorageBlobLogs
| where TimeGenerated between (varStart .. varEnd)
and AccountName == varStorageAccount
| sort by OperationName
Need:
I want to put the various OperationNames (GetBlob, AppendFile, etc.) into a custom order.
Something like:
| sort by OperationName['GetBlob'], OperationName['AppendFile'], OperationName asc
Ideally I'd like to specify values to sort by then allow Kusto to order the remaining using asc/desc.
Is this possible?
Use an aux column, like this:
datatable(OperationName:string, SomethingElse:string)
[
"AppendFile", "3",
"GetBlob", "1",
"AppendFile", "4",
"GetBlob", "2"
]
| extend OrderPriority =
case(OperationName == "GetBlob", 1,
OperationName == "AppendFile", 2,
3)
| order by OrderPriority asc, SomethingElse asc
| project-away OrderPriority
Output:
OperationName
SomethingElse
GetBlob
1
GetBlob
2
AppendFile
3
AppendFile
4

kusto database as string - issues in query

I m getting database name from let statement (dbname) , the issue im getting blank output ,but when I pass the db name [when I give as hardcoded value, the query is working] . please help me to understand what the issue in query.
let view=datatable(Property:string,Value:dynamic)[];
let viewFile=datatable(FileName:string)[];
let dbnameview=datatable(dbname:string)[];
alias database db = cluster(X).database('');
let dbname=tostring(toscalar((
union isfuzzy=true dbnameview, cluster(X).database('$systemdb').Operations
| where Operation == "DatabaseCreate" and Database contains "oci-"| where State =='Completed'
and StartedOn between (datetime(2020-04-09) .. 1d)
| distinct Database , StartedOn
| order by StartedOn desc
| take 1 )));
//let dbname= 'Y';
let latestInfoFile = toscalar((
union isfuzzy=true viewFile,cluster(X).database(dbname).['TextFileLogs']
| where FileName contains "AzureStackStampInformation"
| distinct FileName
| order by FileName
| take 1)) ;
union isfuzzy=true view,(
cluster(X).database(dbname).['TextFileLogs']
| where FileName == latestInfoFile
| distinct LineNumber,FileLineContent
| order by LineNumber asc
| summarize StampInfo=(toobject(strcat_array(makelist(FileLineContent,100000), "\r\n")))
| mvexpand bagexpansion=array StampInfo
| project Property=tostring(StampInfo[0]), Value=StampInfo[1]
)|where Property contains "StampVersion" | project BuildNumber = Value;
what you're attempting to do isn't supported, as mentioned in the docs: https://learn.microsoft.com/en-us/azure/kusto/query/databasefunction

Get the number of execution id wise in toad for oracle

Please help in extracting a data of number of executions against respective id
For e.g. I have temp1 table with data of id and DT where id is given in the form below :
SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439
SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439
SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439
I need the result as below :
id number of exec
28867 2
29329 1
The query is below:
select count(A.DT)
from temp1 a
where A.id like '%28867%'
and A.DT >= to_date( '01-Aug-2017','dd-MON-yyyy')
and A.DT < to_date('01-Sep-2017','dd-MON-yyyy')
The problem i am facing is to extract ids from the column of id using like operator.
Please help me to retrieve the result in TOAD FOR ORACLE
You can use REGEXP_REPLACE function, or a combination of SUBSTR and INSTR functions to extract this number from the string.
The latter is faster than the pattern matching in REGEXP_REPLACE, so if there is a huge table of strings I would use the second option.
Assumming that SUBM~ substring is always before the number, this should work:
With my_data as (
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' as str from dual union all
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' from dual union all
select 'SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439' from dual
)
SELECT
regexp_replace( str, '.*SUBM~(\d+).*', '\1' ) as x,
substr( str,
instr( str, 'SUBM~' ) + length('SUBM~'),
instr( str, '_', instr( str, 'SUBM~' ) )
- instr( str, 'SUBM~' )
- length('SUBM~')
) as y
FROM My_data;
| X | Y |
|-------|-------|
| 28867 | 28867 |
| 28867 | 28867 |
| 29329 | 29329 |

Oracle 11g: Replace part of string using dictionary mapping

Is there any nice trick to change values in string using dictionary mapping? For example I have table1 FIDDLE
+---------------------------+
| ROW1 |
+---------------------------+
| This is an example string |
| This String has typ0s |
+---------------------------+
And some mapping table dict1 FIDDLE:
+-------------------------+
| OLD | NEW |
+-------------------------+
| THIS | THAT |
| IS | ARE |
| EXAMPLE | SOURCE |
| STRING | NUMBER |
+------------+------------+
I need some SELECT statement that will split values in table1.row1 and change words using mapping dictionary dict1 so received values will be ( changing no existing dictionary values to upper is optional):
+---------------------------+
| TRANS_ROW1 |
+---------------------------+
| THAT ARE AN SOURCE NUMBER |
| THAT NUMBER HAS TYP0S |
+---------------------------+
PS. Spliting using REGEXP expression will be so nice..
WITH dict1 AS
(SELECT 'THIS' fr,
'THAT' t
FROM dual
UNION ALL
SELECT 'IS' fr,
'ARE' t
FROM dual
UNION ALL
SELECT 'EXAMPLE' fr,
'SOURCE' t
FROM dual
UNION ALL
SELECT 'STRING' fr,
'NUMBER' t
FROM dual),
table1 AS
(SELECT 'This is an example string' AS str,
1 AS sn
FROM dual
UNION ALL
SELECT 'This String has typ0s' AS str,
2 sn
FROM dual),
src AS
(SELECT regexp_substr(upper(s.str), '[^ ]+', 1, LEVEL) str2,
s.*,
rownum nn
FROM table1 s
CONNECT BY instr(TRIM(' ' FROM str), ' ', 1, LEVEL - 1) > 0
AND PRIOR sn = sn
AND PRIOR dbms_random.value IS NOT NULL),
repl AS
(SELECT nvl2(dict1.t, dict1.t, src.str2) lex,
sn,
nn
FROM src
LEFT JOIN dict1
ON dict1.fr = src.str2)
SELECT listagg(lex, ' ') within GROUP(ORDER BY nn),
sn
FROM repl
GROUP BY sn
It works now as you ask. Enjoy.
EDIT: FIDDLE with solution

Resources