Compare two arrays of strings - KQL - kql

We are trying to compare two arrays of strings and matching keywords/domains from the first array (url1) with url2. Can we use a wild card or alternate way to match keywords/domains in url1 with the whole strings in url2?
Sample Query:
let url1 = dynamic(["test2.com","test4.com"]); let url2 = dynamic( ["test.com", "test2.com/1234/", "test3.com"]); print result = set_difference(url2,url1)
Current Results:
["test.com","test2.com/1234/","test3.com"]
Expected Results:
["test.com","test3.com"]

let url1 = dynamic(["test2.com","test4.com"]);
let url2 = dynamic( ["test.com", "test2.com/1234/", "test3.com"]);
let url2_clean = toscalar(print url = url2 | mv-apply url to typeof(string) on (summarize make_list(trim_end("/.*", url))));
print result = set_difference(url2_clean, url1)
result
["test.com","test3.com"]
Fiddle
In case you need it on a row-level:
print url1 = dynamic(["test2.com","test4.com"]), url2 = dynamic( ["test.com", "test2.com/1234/", "test3.com"])
| mv-apply url2 to typeof(string) on (summarize url2_clean = make_list(trim_end("/.*", url2)))
| project result = set_difference(url2_clean, url1)
result
["test.com","test3.com"]
Fiddle

Related

Split character from string in Idiomatic way Kotlin

Hey I am working in kotlin. I have one string in which I want to split into list from there where I should provide character. I'll explain in details
For example 1
val string = "Birth Control"
val searchText = "n"
Output
["Birth Co", "trol"]
For example 2
val string = "Bladder Infection"
val searchText = "i"
Actual Output
["Bladder ", "nfect", "on"]
Expect Output
["Bladder ", "nfection"]
I tried some code but example 1 is working fine but example 2 is not because I only want to split first occurrence.
val splitList = title?.split(searchText, ignoreCase = true)?.toMutableList()
splitList?.remove(searchText)
Can someone guide me how to solve this idiomatic way. Thanks
You miss the limit option of the split function. If you give it a value of 2 the result list will have a maximum of 2 entries:
val result = "Bladder Infection".split("i", ignoreCase = true, limit = 2)

Passing a variable into SQL string

I'm modifying someone else's showershell script that's used within our database to try and have it do some extra steps behind the scenes: reject code, location code, and start date.
It starts by asking for 3 values to pass as variables, but I want to add 2 additional values using a dictionary based on the location code. I don't want to share the entire batch - I know it works without this one specific part, but I'll include enough to illustrate my point.
The issue is with the variables $AREA1 and $AREA2 - these are what I'm trying to add.
The "parameters" are being injected using one way where it asks for the user to supply them but i don't want the user to supply these, they're supposed to be a lookup.
For instance, if the LOC was 5300 then AREA1 should be 101 and AREA 2 should be 111.
param(
[ImdsParameter(FullName = "REJ_CODE", Description = "Enter a 4 digit reject code to filter the data. Will not run without one.", Length = 4)]
[string] $REJ,
[ImdsParameter(FullName = "LOC", Description = "The Location code you want to run this against. Example 5300.", Length = 4)]
[string] $LOC,
[ImdsParameter(FullName = "STDTE", Description = "Start date. This is the start date from how back to run the report. Example 2021-01-01", Length = 10)]
[string] $STDTE
)
$areaStart = #{
5300 = 101 ;
5304 = 112 ;
5305 = 123 ;
5306 = 134 ;
//there’s well over 100 of these
}
$areaEnd = #{
5300 = 111 ;
5304 = 122 ;
5305 = 133 ;
5306 = 144 ;
//same
}
$AREA1 = $areaStart.Get_Item($LOC)
$AREA2 = $areaEnd.Get_Item($LOC)
$jobSql = #"
SELECT TB1.dataitem1,
TB1. Dataitem2,
TB1. Dataitem3,
TB2. Dataitem1
FROM firstTable AS TB1 INNER JOIN secondTable AS TB2
ON TB1. dataitem = TB2. dataitem
WHERE TB1.LOCATION = #LOC AND TB2.AREA BETWEEN '$($AREA1)' AND '$($AREA2)'
"#
$edbms = Get-Rdms -SQL $jobSql -Parameters #{LOC = $LOC; REJ = $REJ; STDTE = $STDTE; }
$edbms | ConvertTo-Csv -NoTypeInformation
EDIT: I need to add that the script will run, but returns no data. If I just plug the SQL in with all the values manually, it will run just fine.
Thank you for your time.
The values in the SQL were being treated as strings while the values in the dictionaries were being treated as numbers.
I changed this:
5300 = 101 ;
5304 = 112 ;
5305 = 123 ;
5306 = 134 ;
To this:
'5300' = '101' ;
'5304' = '112' ;
'5305' = '123' ;
'5306' = '134' ;
And it provided the data expected.

sending string parameter in action=track leanplum Rest Api not working

I want to send string parameters in Leanplum api using action script
Eg param:{"Element":"Hi"}
var request:URLRequest = new URLRequest("https://www.leanplum.com/api");
request.method = URLRequestMethod.GET;
var variables:URLVariables = urlVariables;
variables.userId = userId;
variables.event = eventName;
var params:Object = new Object();
params.Element = "Hi";
var paramStr:String = JSON.stringify(params);
variables.params = paramStr;
variables.appId = appId;
variables.clientKey = clientKeyProduction;
variables.apiVersion = apiVersion;
variables.action = "track";
variables.versionName = AppInfo.getInstance().appVersion;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, function(e:Event):void {
trace(e.target.data);
});
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
trace(e.target.data);
});
loader.load(request);
This is actual Request (App ID and ClientKey are dummy):
https://www.leanplum.com/api?clientKey=V42fKaJaBuE&userId=1010&params={"Element":"Ur"}&appId=HEVdDlXiBVLwk&event=Element_Opened&action=track&versionName=2.3.0&apiVersion=1.0.6&info=Lu
Encoded Request:
https://www.leanplum.com%2Fapi%3FclientKey%3DV42fKaJaBuE%26userId%3D1010%26params%3D%7B%22Element%22%3A%22Ur%22
%7D%26appId%3DHEVdDlXiBVLwk%26event%3DElement_Opened%26action%3Dtrack%26versionName%3D2.3.0%26apiVersion%3D1.0.6%26info%3DLu
if I run above request in any rest client I get the same status success : true .
I am getting the response {"response": [{"success": true}]} but I can't find the parameters with value string in Leanplum dashboard, its listing parameter name but not the String Value for parameter.
If you apply some combination of filters then you can see values of parameter you sent to leanplum. like First select the occurrence of some event then apply Group by parameter then select parameter you want to see the data for.
Its a little different from flurry, Google analytics etc.

How to find the filename without the extension through JQuery

I am hoping to find only the filename within the current page URL.
So if the URL is
www.ex.com/des/filename.php
or
www.ex.com/des/filename.php#9
I need to get only
filename
I tried this, but it doesn't work.
var loc = window.location;
var fileNameIndex = loc.lastIndexOf("/") + 1;
var output = loc.substr(0, loc.lastIndexOf('.')) || loc;
Thanks
var loc = window.location.href;
var output = loc.split('/').pop().split('.').shift()
This works for me:
var loc = window.location.href
var fileNameIndex = loc.lastIndexOf("/") + 1;
var dotIndex = loc.lastIndexOf('.');
var output = loc.substr(fileNameIndex, dotIndex < fileNameIndex ? loc.length : dotIndex);
For an explanation of the code: What it does is, it takes the text between the last "/" and the last ".", provided the "." occurs after the "/", otherwise it just takes everything from the last "/" to the end of the string.

C# RegEx.Matches doesn't return all submatches inside expression unlike RegEx.Replace

Could you help me to understand what is wrong. I have usual SQL query :
var SQL = "SELECT [Extent1].[RouteID] AS [RouteID]
FROM [RoutesEntities].[Routes] AS [Extent1]\r\n
INNER JOIN [dbo].[Locales] AS [Extent2]
ON [Extent2].[LocaleID] = [Extent1].[LocaleID]";
And i need to define location of FROM part till its AS alias.
I did the following with RegEx.Replace :
var pattern = #"(FROM[^(SELECT)]+?Routes.+?AS.+?\[?([^\]\s]+)\]?)";
var result = Regex.Replace(SQL, pattern, "$1 $2", RegexOptions.Singleline | RegexOptions.IgnoreCase);
And it works fine - this will return :
match_$1 = "FROM [RoutesEntities].[Routes] AS [Extent1]";
match_$2 = "Extent1";
BUT! If i try to use Regex.Matches with the same options and same input string ... it finds only one match.
MatchCollection queryPlace = Regex.Matches(
SQL,
#"(FROM[^(SELECT)]+?Routes.+?AS.+?\[?([^\]\s]+)\]?)",
RegexOptions.IgnoreCase | RegexOptions.Singleline
);
match_$1 = "FROM [RoutesEntities].[Routes] AS [Extent1]";
WHY??? Is this a bug, or i should create a separate named group for each sub expression? Does anybody know why this happens, why only first match was found?
P.S. Regex is correct - i'm sure, you can check it here - http://www.gskinner.com/RegExr/
Thank, Artem
Sorry, I think i was so stupid because i did not know how exactly Regex.Matches method works and now i understood that in any case i should use Regex.Match and its "Groups" property :
Match queryPlace = Regex.Match(
_queryData.CommandText,
#"(FROM[^(SELECT)]+?" + tableInner + #".+?AS.+?\[?([^\]\s]+)\]?)",
RegexOptions.IgnoreCase | RegexOptions.Singleline
);
String innerAlias = "";
var d = queryPlace.Groups[0]; // FROM [RoutesEntities].[Routes] AS [Extent1]
var d1 = queryPlace.Groups[1]; // FROM [RoutesEntities].[Routes] AS [Extent1]
var d2 = queryPlace.Groups[2]; // Extent1
Sorry for disturbing, answer is found.