Filter stringset that contain string with substring? - amazon-dynamodb

My column value is a string set, how do i filter string set with string that contain a substring
For example
entry1 :
{
ss : [
"TRUE_item",
"FALSE_item"
]
}
entry2 :
{
ss : [
"FASE_item",
"FALSE_item"
]
}
How to i filter entry wihich contain ss that have an element contain TRUE, which in this case should return entry 1?

You cannot. You must give the entire value to match a string within a set.

Related

Terraform: Add item to a DynamoDB Table

What is the correct way to add tuple and key-pair values items to a DynamoDB database via Terraform?
I am trying like this:
resource "aws_dynamodb_table_item" "item" {
table_name = aws_dynamodb_table.dynamodb-table.name
hash_key = aws_dynamodb_table.dynamodb-table.hash_key
for_each = {
"0" = {
location = "Madrid"
coordinates = [["lat", "40.49"], ["lng", "-3.56"]]
visible = false
destinations = [0, 4]
}
}
item = <<ITEM
{
"id": { "N": "${each.key}"},
"location": {"S" : "${each.value.location}"},
"visible": {"B" : "${each.value.visible}"},
"destinations": {"L" : [{"N": "${each.value.destinations}"}]
}
ITEM
}
And I am getting the message:
each.value.destinations is tuple with 2 elements
│
│ Cannot include the given value in a string template: string required.
I also have no clue on how to add the coordinates variable.
Thanks!
List should be something like that :
"destinations": {"L": [{ "N" : 1 }, { "N" : 2 }]}
You are trying to pass
"destinations": {"L": [{ "N" : [0,4] }]}
Also you are missing the last } in destinations key
TLDR: I think the problem here is that you are trying to put L(N) - i.e. a list of numeric values, while your current Terraform code tries to put all the destinations into one N/number.
Instead of:
[{"N": "${each.value.destinations}"}]
you need some iteration over destinations and building a {"N": ...} of them.
"destinations": {"NS": ${jsonencode(each.value.destinations)}}
Did the trick!

Get an array of specific parameters from Image Collection of Google Earth Engine

I've got an Image Collection like:
ImageCollection : {
features : [
0 : {
type: Image,
id: MODIS/006/MOD11A1/2019_01_01,
properties : {
LST_Day_1km : 12345,
LST_Night_1km : 11223,
system:index : "2019-01-01",
system:asset_size: 764884189,
system:footprint: LinearRing,
system:time_end: 1546387200000,
system:time_start: 1546300800000
},
1 : { ... }
2 : { ... }
...
],
...
]
From this collection, how can I get an array of objects of specific properties? Like:
[
{
LST_Day_1km : 12345,
LST_Night_1km : 11223,
system:index : "2019-01-01"
},
{
LST_Day_1km : null,
LST_Night_1km : 11223,
system:index : "2019-01-02"
}
...
];
I tried ImageCollection.aggregate_array(property) but it allows only one parameter at one time.
The problem is that the length of "LST_Day_1km" is different from the length of "system:index" because "LST_Day_1km" includes empty values, so it's hard to combine arrays after get them separately.
Thanks in advance!
Whenever you want to extract data from a collection in Earth Engine, it is often a straightforward and efficient strategy to first arrange for the data to be present as a single property on the features/images of that collection, using map.
var wanted = ['LST_Day_1km', 'LST_Night_1km', 'system:index'];
var augmented = imageCollection.map(function (image) {
return image.set('dict', image.toDictionary(wanted));
});
Then, as you're already familiar with, just use aggregate_array to extract that property's values:
var list = augmented.aggregate_array('dict');
print(list);
Runnable complete example:
var imageCollection = ee.ImageCollection('MODIS/006/MOD11A1')
.filterDate('2019-01-01', '2019-01-07')
.map(function (image) {
// Fake values to match the question
return image.set('LST_Day_1km', 1).set('LST_Night_1km', 2)
});
print(imageCollection);
// Add a single property whose value is a dictionary containing
// all the properties we want.
var wanted = ['LST_Day_1km', 'LST_Night_1km', 'system:index'];
var augmented = imageCollection.map(function (image) {
return image.set('dict', image.toDictionary(wanted));
});
print(augmented.first());
// Extract that property.
var list = augmented.aggregate_array('dict');
print(list);
https://code.earthengine.google.com/ffe444339d484823108e23241db04629

How to use Unicode in Regex

I am writing one regex to find rows which matches the Unicode char in text file
!Regex.IsMatch(colCount.line, #"^"[\p{IsBasicLatin}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]"+$")
below is the full code which I have written
var _fileName = #"C:\text.txt";
BadLinesLst = File
.ReadLines(_fileName, Encoding.UTF8)
.Select((line, index) =>
{
var count = line.Count(c => Delimiter == c) + 1;
if (NumberOfColumns < 0)
NumberOfColumns = count;
return new
{
line = line,
count = count,
index = index
};
})
.Where(colCount => colCount.count != NumberOfColumns || (Regex.IsMatch(colCount.line, #"[^\p{IsBasicLatin}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]")))
.Select(colCount => colCount.line).ToList();
File contains below rows
264162-03,66,JITK,2007,12,874.000 ,0.000 ,0.000
6420œ50-00,67,JITK,2007,12,2292.000 ,0.000 ,0.000
4804¥75-00,67,JITK,2007,12,1810.000 ,0.000 ,0.000
If file of row contains any other char apart from BasicLatin or LatinExtended-A or LatinExtended-B then I need to get those rows.
The above Regex is not working properly, this is showing those rows as well which contains LatinExtended-A or B
You need to just put the Unicode category classes into a negated character class:
if (Regex.IsMatch(colCount.line,
#"[^\p{IsBasicLatin}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]"))
{ /* Do sth here */ }
This regex will find partial matches (since the Regex.IsMatch finds pattern matches inside larger strings). The pattern will match any character other than the one in \p{IsBasicLatin}, \p{IsLatinExtended-A} and \p{IsLatinExtended-B} Unicode category sets.
You may also want to check the following code:
if (Regex.IsMatch(colCount.line,
#"^[^\p{IsBasicLatin}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]*$"))
{ /* Do sth here */ }
This will return true if the whole colCount.line string does not contain any character from the 3 Unicode category classes specified in the negated character class -or- if the string is empty (if you want to disallow fetching empty strings, replace * with + at the end).

Xcode how to split substring in two substrings

I have a NSString. This NSString is split in different parts with ";".
I split this NSString in 2 substrings (with [componentsSeparatedByString:#";"])
Now, I have a substring, with [componentsSeparatedByString:#";"], in a NSArray.
In this substring I have (sometimes but not always !) a ",".
When I have a "," I want to spilt my substring in two "sub-substrings" and use this two sub-subtrings...
How can I do that ?
Thanks for your answers.
EDIT :
Hi #Alladinian, thanks for ur answer.
That's a loop I need, I think. I want to add new contact to iPhone address book (First name and Last name) with QRCode.
My NSString looks like :
NSString *_name = [NSString stringWithFormat:#"%#", code.contact];
My substring looks like:
NSArray *subStrings = [code.contact componentsSeparatedByString:#";"];
In my NSString, I have (perhaps but not always) a "," I need two different outputs : one for first name and one for last name.
I know how to add first name and last name separated by "," but I don't know what to do if I have only a first name. Have only a first name crash my app...
For now, to skirt problem, I send Fist name and Last name in Fist name field... But it's not perfect for my sake.
Ok, here's some code you can use. You can't just use componentsSeparatedByString for the name because there are 4 cases:
no comma: assume just first name "first"
comma, but no last name ", first"
comma, but no first name "last, "
comma, both: "last, first"
code:
NSString * mecardString = ...your string...
if ( [ mecardString hasPrefix:#"MECARD:" ] ) // is it really a card string? (starts with 'MECARD:')
{
mecardString = [ mecardString substringFromIndex:[ #"MECARD:" length ] ] ; // remove MECARD: from start
NSString * firstName = nil ;
NSString * lastName = nil ;
NSArray * components = [ mecardString componentsSeparatedByString:#";" ] ;
for( NSString * component in components ) // process all parts of MECARD string
{
NSString * lcString = [ component lowercaseString ] ;
if ( [ lcString hasPrefix:#"n:" ] )
{
// handle name ("N:")
NSRange commaRange = [ lcString rangeOfString:#"," ] ;
if ( commaRange.location == NSNotFound )
{
firstName = lcString ;
}
else
{
firstName = [ lcString substringFromIndex:NSMaxRange( commaRange ) ] ;
lastName = [ lcString substringToIndex:commaRange.location ] ;
}
NSCharacterSet * whitespaceCharSet = [ NSCharacterSet whitespaceAndNewlineCharacterSet ] ;
firstName = [ firstName stringByTrimmingCharactersInSet:whitespaceCharSet ] ;
lastName = [ firstName stringByTrimmingCharactersInSet:whitespaceCharSet ] ;
}
else if ( lcString hasPrefix:#"sound:" )
{
// handle name ("SOUND:")
}
// ... write code handle other parts of MECARD... (NICKNAME, BDAY, URL, etc)
else
{
// handle unknown case here
}
}
// you have names here
}

Cannot convert type "char" to "string" in Foreach loop

I have a hidden field that gets populated with a javascript array of ID's. When I try to iterate the hidden field(called "hidExhibitsIDs") it gives me an error(in the title).
this is my loop:
foreach(string exhibit in hidExhibitsIDs.Value)
{
comLinkExhibitToTask.Parameters.AddWithValue("#ExhibitID", exhibit);
}
when I hover over the .value it says it is "string". But when I change the "string exhibit" to "int exhibit" it works, but gives me an internal error(not important right now).
You need to convert string to string array to using in for loop to get strings not characters as your loop suggests. Assuming comma is delimiter character in the hidden field, hidden field value will be converted to string array by split.
foreach(string exhibit in hidExhibitsIDs.Value.Split(','))
{
comLinkExhibitToTask.Parameters.AddWithValue("#ExhibitID", exhibit);
}
Value is returning a String. When you do a foreach on a String, it iterates over the individual characters in it. What does the value actually look like? You'll have to parse it correctly before you try to use the data.
Example of what your code is somewhat doing right now:
var myString = "Hey";
foreach (var c in myString)
{
Console.WriteLine(c);
}
Will output:
H
e
y
You can use Char.ToString in order to convert
Link : http://msdn.microsoft.com/en-us/library/3d315df2.aspx
Or you can use this if you want convert your tab of char
char[] tab = new char[] { 'a', 'b', 'c', 'd' };
string str = new string(tab);
Value is a string, which implements IEnumerable<char>, so when you foreach over a string, it loops over each character.
I would run the debugger and see what the actual value of the hidden field is. It can't be an array, since when the POST happens, it is converted into a string.
On the server side, The Value property of a HiddenField (or HtmlInputHidden) is just a string, whose enumerator returns char structs. You'll need to split it to iterate over your IDs.
If you set the value of the hidden field on the client side with a JavaScript array, it will be a comma-separated string on the server side, so something like this will work:
foreach(string exhibit in hidExhibitsIDs.Value.Split(','))
{
comLinkExhibitToTask.Parameters.AddWithValue("#ExhibitID", exhibit);
}
public static string reversewordsInsentence(string sentence)
{
string output = string.Empty;
string word = string.Empty;
foreach(char c in sentence)
{
if (c == ' ')
{
output = word + ' ' + output;
word = string.Empty;
}
else
{
word = word + c;
}
}
output = word + ' ' + output;
return output;
}

Resources