I have a statement where I try to concatenate logs (strings) together to a single string.
Something like this
ContainerLog
| where conditions
| summarize strcat(LogEntry)
However I cant figure out how to concatenate strings like this since strcat is not an aggregating function. I need something else but don't know what.
How can I do this?
For example if I have log entries "1","2","3" the final result should be "123"
This allows a distinct combination in concrete.
requests
| where URL contains "prod"
| summarize count(), code=make_set(resultCode) by name
| sort by count_ desc
Reference: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/summarizeoperator, https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/makeset-aggfunction
Related
I have a scenario where I used pipe characters to introduce a list of items for a better readability:
Scenario: Search users
Then I should see the user list with the following columns:
| Name |
| Age |
| DOB |
| Address|
The items in the list are non-parameterised, so the scenario will only run once.
I created the step definition for the step like this:
#Then("I should see the user list with the following columns:")
On execution, the test was not found and I got the error: io.cucumber.core.gherkin.FeatureParserException: Failed to parse resource at: classpath:features
If I remove pipe characters and condense the list like this, then the test works fine:
Then I should see the user list with the following columns: Name, Age, DOB, Address
I am not sure how step definitions handle a step with a list of non-parameterised items having pipe characters, without cucumber thinking the step has a parameter
The first convention
Then I should see the user list with the following columns:
| Name |
| Age |
| DOB |
| Address|
resembles a scenario with at data table as parameters. For this to work, your step definition method must have a DataTable argument.
#Given ("I should see the user list with the following columns:")
public void verifyUserList(DataTable table) {
// Your logic here
}
Depending on the table, you will have to convert it to some kind of list. A single column list like the one here, should convert to List<String>. A row with multiple columns should convert to a <List<List<String>>. It is up to you to code the conversion correctly. A quick search on Cucumber Data Tables should help you code this correctly.
Another similar convention is Scenario Outline. For scenario outlines to be valid, the test must be tagged with Scenario Outline and the table with Examples. For instance:
Scenario: Search users
Then I should see the user list with the following columns:
| col1 | col2 | col3 | col4 |
| Name | Age | DOB | Address |
The examples table should contain at least two rows: the top row for the variable names, and the second and subsequent rows for the values. So, if you want to check the column names for 5 database tables, you will have 5 rows of values and each row will be processed in its own test run. For this case, the step definition should look something like this:
#Given ("I should see the user list with the following columns: <col1> <col2> <col3> <col4>")
public void verifyUserList(String col1, String col2, String col3, String col4) {
// Your logic here
}
The name of the variables don't need to match the identifiers inside the angular braces. However, they must match the column headers on the examples table.
The last convention, is a single test step with four values. In this case, value is substituted in the step definition during a single test run.
Basically, each format has distinct requirements. Now, to answer why the first one didn't work, it should all boil down to the method mapped to the Cucumber step. My guess is that it doesn't contain a data table as an argument.
In T-SQL, when grouping results, you can also get a running total row when specifying "WITH ROLLUP".
How can i achieve this in Kusto? So, consider the following query:
customEvents | summarize counter = count() by name
The query above gives me a list of event names, and how often they occurred. This is what i need, but i also want a row with the running total (the count of all events).
It feels like there should be an easy way to achieve this, but i havent found anything in the docs ...
You can write 2 queries, the first query is used to count the number of each events, the second query is used to count the numbers of all the events. Then use the union operator to join them.
The query like below:
customEvents
| count
| extend name = "total",counter=Count
| project name,counter
| union
(customEvents
| summarize counter = count() by name)
Test result is as below:
I'm looking for examples of the code using python3, no links to the documentation. I havent found examples in the documentation.
I'm looking to query 2 elements with the category "red" starting at the ID 1.
This is my table:
| ID | category | description |
| 0 | red | .... |
| 1 | red | .... |
| 2 | blue | .... |
| 3 | red | .... |
| 4 | red | .... |
The query should return the elements with the id 1 and 3.
Looking forward to read your examples. Thanks in advance.
In dynamo Db you query over your PartitionKey, LSIs or GSIs.
In your case I would create a GSI with its' partitionKey (gsiID) as your category and its' sortKey (gsiSK) as your ID.
In that case you can do a query like this: query all elements with gsiID = red and gsiSK = *
This will give you all the reds sorted by their ID in ascending order (you can also specify descending order)
Now dynamo queries have an option to limit your result. Since you need to you can do a limit = 2.
I hope this will help you!
You need to define an Global secondary index in which the partition key is category and the sort key is id.
Once your have that index defined, you can query it as follows (I am using the JS notation, sorry):
{
TableName: 'your_table_name',
IndexName: 'your_index_name',
KeyConditionExpression: 'category = :x and ID >= :y',
ExpressionAttributeValues: {
':x': 'red',
':y': 1
}
}
Note that this is a query. In DynamoDB, queries work on "chunks" of items (aka: "pages"). Specifically, when executing a query, DDB takes a chunk, finds all matching items in that chunks and returns them. If there are other matching items in other chunks they will not be returned. However, the response will provide you with details of the next chunk so that you can issue a subsequent query on the next chunk. These "details" are encapsulated in the LastEvaluatedKey field of the response and they should be copied into the ExclusiveStartKey of the subsequent request.
You can check this guide to see an example of using LastEvaluatedKey. Look for the following line:
while 'LastEvaluatedKey' in response:
Important!
Although you want to get just two items, you do not want to set the Limit field to 2. Setting it to 2 means that DynamoDB will use very small chunks when looking for items that match your query (in fact, it will use chunks of just two items): this means you will need to do numerous repeated queries (by using LastEvaluatedkey/ExclusiveStartKey as explained above) until you actually find two matching items. This will considerably slow down the entire process. For most practical scenarios, the best thing to do is not to set the Limit field at all, and just use its default value.
I am writing kusto queries to analyze the state of the database when simple queries run for a long time.
For ex: data and type = SQL in dependencies is a sql server query. If its duration at timestamp 2019-06-24T16:41:24.856 is >= 15000 (>= 15 secs)
I would like to query and analyze the dtu_consumption_percent out of AzureMetrics from 2019-06-24T16:40:24.856 to 2019-06-24T16:42:24.856. ( 1 min before and 1 min after the query completion time) to determine the state of the database at that point in time.
Question: I wonder if anyone can give me pointers on getting the database name out of the target column from dependencies?
target looks as below:
tcp:sqlserver-xxx-xxxxxx.database.windows.net | DDDDD
and I am needing to extract DDDDD to join to AzureMetrics column Resource.
Thank you!
As Yoni says you can use parse, or you could use substring:
let T = datatable(Value:string) [
'tcp:sqlserver-xxx-xxxxxx.database.windows.net | DDDDD',
'udp:appserver-yyy-yyyyyy.database.contoso.com | EEEEE'
];
T
// Look for the pipe and take everything after it as the value
| extend ToSubstring = substring(Value, indexof(Value, "|")+1)
https://learn.microsoft.com/en-us/azure/kusto/query/substringfunction
However if you find yourself doing this a lot you may want to take a look at Custom Fields:
https://learn.microsoft.com/en-us/azure/azure-monitor/platform/custom-fields
You could use the parse operator:
https://learn.microsoft.com/en-us/azure/kusto/query/parseoperator
print value = 'tcp:sqlserver-xxx-xxxxxx.database.windows.net | DDDDD'
| parse value with * "| " database
this returns:
| value | database |
|-------------------------------------------------------|----------|
| tcp:sqlserver-xxx-xxxxxx.database.windows.net | DDDDD | DDDDD |
I have one column in my table in Postgres let's say employeeId. We do some modification based on the employee type and store it in DB. Basically, we append strings from these 4 strings ('ACR','AC','DCR','DC'). Now we can have any combination of these 4 strings appended after employeeId. For example, EMPIDACRDC, EMPIDDCDCRAC etc. These are valid combinations. I need to retrieve EMPID from this. EMPID length is not fixed. The column is of varying length type. How can this be done in Postgres?
I am not entirely sure I understand the question, but regexp_replace() seems to do the trick:
with sample (employeeid) as (
values
('1ACR'),
('2ACRDCR'),
('100DCRAC')
)
select employeeid,
regexp_replace(employeeid, 'ACR|AC|DCR|DC.*$', '', 'gi') as clean_id
from sample
returns:
employeeid | clean_id
-----------+---------
1ACR | 1
2ACRDCR | 2
100DCRAC | 100
The regular expression says "any character after any of those string up to the end of the string" - and that is then replace with nothing. This however won't work if the actual empid contains any of those codes that are appended.
It would be much cleaner to store this information in two columns. One for the empid and one for those "codes"