Question: I have a problem where I need to build a Python dictionary with a given string.
The string has a certain pattern as follows:

```
string = 'streetName=BENEDITO DE PAULA, QD 03 LT 03, state=AM, complement=SJ BANDEIRANTES, number=4, country=BRA'

```

The split cannot be done by comma, because there is a comma in the middle of the text that needs to become a string.
I need the split to be done by generating the following list below so that later it becomes a dictionary
The keys of dictionary is separet per equal sinal (=) and value is subsequent text.

```
list = ['streetName=BENEDITO DE PAULA, QD 03 LT 03', 'state=AM', 'complement=SJ BANDEIRANTES', 'number=4', 'country=BRA']

```

So I need to generate a list from a regex that I believe should consider the text `(, TEXT=)`

Then I will generate a dictionary as follows

```
dict(v.split("=") for v in re.split("(REGEX)", string))

```

Was using the function below, but it does not solve the problem for this case

```
def convert_to_json(x):
    dic = dict(v.split("=") for v in x.split(","))
    return json.dumps({k.strip():v for (k,v) in dic.items()})

```

Answer: 
Okay, after some more digging, I think I found the right thing on the (sparse) [documentation](https://docs.aws.amazon.com/timestream/latest/developerguide/sample-queries.devops-scenarios.html#sample-queries.devops-scenarios.example-queries). Subqueries are the answer!

```sql
WITH binned_query AS (
SELECT BIN(time,1d) AS "day_time",
dimension_name AS "series",count(measure_name) AS "metric" 
FROM "event"."data" WHERE "measure_name" = 'code' 
AND $__timeFilter 
GROUP BY BIN(time,1d),dimension_name order by 1
)
SELECT series, CREATE_TIME_SERIES(day_time,metric) 
FROM binned_query 
GROUP BY series

```

Displays beautifully in grafana:
[![enter image description here](https://i.stack.imgur.com/wydni.png)](https://i.stack.imgur.com/wydni.png)
This solution works only if you don't have a lot of data points. If I filter for the last days i'm fine, but if I would like to get the last 30 days I'm getting an error from the AWS TimeStream: "Query aborted as max page response size has been exceeded by the output result row".
The fact is that I'm trying to group 40247 data points.
[![This is the query](https://i.stack.imgur.com/fNN3F.png)](https://i.stack.imgur.com/fNN3F.png)

Any help will be much appreciated. I have to say that I first used MySQL and it worked easily, when I moved to AWS TimeStream I facing some issues.