Couchbase select query performance - couchbase

I have simple SELECT QUERY which takes more than 3 seconds to get the result. Actual result count is 15211
Query:
select meta().id assetId, modelAndPart.partNumberID,assetLocation.id locationId from ic_v10_mammoet where type = 'asset' and modelAndPart IS NOT null and tenantId='439'
EXPLAIN:
{
"requestID": "cda5ed1b-efaf-4c5b-bb67-81f0a3542324",
"clientContextID": "13583a95-04cc-4722-90dd-9642068f9ea0",
"signature": "json",
"results": [
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan",
"index": "type_idx",
"index_id": "f1d17cd15ab5feb6",
"keyspace": "ic_v10_mammoet",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"asset\""
],
"Inclusion": 3,
"Low": [
"\"asset\""
]
}
}
],
"using": "gsi"
},
{
"#operator": "Fetch",
"keyspace": "ic_v10_mammoet",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "((((`ic_v10_mammoet`.`type`) = \"asset\") and ((`ic_v10_mammoet`.`modelAndPart`) is not null)) and ((`ic_v10_mammoet`.`tenantId`) = \"439\"))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"as": "assetId",
"expr": "(meta(`ic_v10_mammoet`).`id`)"
},
{
"expr": "((`ic_v10_mammoet`.`modelAndPart`).`partNumberID`)"
},
{
"as": "locationId",
"expr": "((`ic_v10_mammoet`.`assetLocation`).`id`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
},
"text": "select meta().id assetId, modelAndPart.partNumberID,assetLocation.id locationId from ic_v10_mammoet where type = 'asset' and modelAndPart IS NOT null and tenantId='439'"
}
],
"status": "success",
"metrics": {
"elapsedTime": "15.0015ms",
"executionTime": "15.0015ms",
"resultCount": 1,
"resultSize": 3009
}
}

Yes, you forgot to ask a question. You can use this index.
CREATE INDEX idx_assets ON somedata
( tenantId, modelAndPart.partNumberID, assetLocation.id )
WHERE type = 'asset';

Related

Inserting a Complex Nested JSON Column in MySQL

Here is my use case :-
I am trying to get the deployment details in a JSON format using :
kubectl get deployment -o json depl_name
and inserting result back to a column: meta_data in MySQL. The column data type is json . But the insert statement is failing with error :-
ERROR 3140 (22032): Invalid JSON text: "Missing a comma or '}' after an object member." at position 1035 in value for column
Here is my entire JSON :-
{
"uuid": {
"view": "demoBoard",
"demo": [
{
"serviceName": "wordpress-backend",
"configurations": {
"ec2_iam": {
"user": [],
"roles": null,
"permissions": null
}
},
"deployment_config": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "6",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"wordpress-backend\",\"wordpress_app_id\":\"w26\"},\"name\":\"wordpress-backend\",\"namespace\":\"wordpress\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"wordpress-backend\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"wordpress-backend\",\"wordpress_app_id\":\"w26\"}},\"spec\":{\"containers\":[{\"envFrom\":[{\"configMapRef\":{\"name\":\"wordpress-backend-config\"}}],\"image\":\"docker-image\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"wordpress-backend\",\"ports\":[{\"containerPort\":8000}],\"resources\":{},\"volumeMounts\":[{\"mountPath\":\"/tmp/me/cloud\",\"name\":\"my-key\"}]}],\"imagePullSecrets\":[{\"name\":\"my-json\"}],\"volumes\":[{\"name\":\"my-cloud-key\",\"secret\":{\"defaultMode\":123,\"secretName\":\"my-key\"}}]}}}}\n"
},
"creationTimestamp": "2022-09-12T13:56:34Z",
"generation": 7,
"labels": {
"app": "wordpress-backend",
"wordpress_app_id": "w26"
},
"name": "wordpress-backend",
"namespace": "wordpress",
"resourceVersion": "v2",
"uid": "0da99b29"
},
"spec": {
"progressDeadlineSeconds": 600,
"replicas": 1,
"revisionHistoryLimit": 10,
"selector": {
"matchLabels": {
"app": "wordpress-backend"
}
},
"strategy": {
"rollingUpdate": {
"maxSurge": "25%",
"maxUnavailable": "25%"
},
"type": "RollingUpdate"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "wordpress-backend",
"wordpress_app_id": "267"
}
},
"spec": {
"containers": [
{
"envFrom": [
{
"configMapRef": {
"name": "wordpress-backend-config"
}
}
],
"image": "docker.io/my-image",
"imagePullPolicy": "IfNotPresent",
"name": "wordpress-backend",
"ports": [
{
"containerPort": 8000,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/my/path/cloud",
"name": "my-key"
}
]
}
],
"dnsPolicy": "ClusterFirst",
"imagePullSecrets": [
{
"name": "my-key"
}
],
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"terminationGracePeriodSeconds": 30,
"volumes": [
{
"name": "my-key",
"secret": {
"defaultMode": 123,
"secretName": "sampleKeyName"
}
}
]
}
}
},
"status": {
"availableReplicas": 1,
"conditions": [
{
"lastTransitionTime": "2022-09-29T15:11:14Z",
"lastUpdateTime": "2022-09-29T15:11:14Z",
"message": "Deployment has minimum availability.",
"reason": "MinimumReplicasAvailable",
"status": "True",
"type": "Available"
},
{
"lastTransitionTime": "2022-09-12T14:20:35Z",
"lastUpdateTime": "2022-09-30T14:13:08Z",
"message": "ReplicaSet \"wordpress-backend-abc123\" has successfully progressed.",
"reason": "NewReplicaSetAvailable",
"status": "True",
"type": "Progressing"
}
],
"observedGeneration": 7,
"readyReplicas": 1,
"replicas": 1,
"updatedReplicas": 1
}
}
}
]
}
}
I guess, because of escape sequence in below line causing the failure :-
"message": "ReplicaSet \"wordpress-backend-abc123\" has successfully progressed.", tried removing that, but no luck.

extract collection from json based on a condition using logic app

I am trying to Extract and sum a particular value using group by from json collection in azure logic app. Trying to achieve this by applying "Condition" connector. My Json file looks like below:
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1",
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1",
},
]
}
]
I want to calculate the sum of Qty group by I_Id from array Res using logic app connector "Condition".
Note: As Res is an array, there can be repetition I_Id with same value, hence, the requirement to get the Qty count based on I_Id
There are few ways to achieve your requirement but here is one of the workaround that worked when reproduced from our end.
Firstly, I have initialised a temporary integer variable to iterated inside the "Res" Array using Until Loop by checking the length of "Res" using the below expression.
length(body('Parse_JSON')?['Release']?[0]?['Res'])
Inside Until I have used condition action to check if I_Id is same using the below expression to the left.
body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['I_Id']
and below expression to the right
body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['I_Id']
Then if the condition satisfies I'm adding the Qty using the expression as below.
add(body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['Qty'],body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['Qty'])
Here is the flow of my logic app
[Optional step]
Considering the bigger picture, I have initialzed another variable quantity and added the resultant of Compose 4 to Qty variable
RESULTS:
Considering the below sample JSON
{
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 5,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
}
]
}
]
}
Here is the result
To avoid confusion try the below code view in your resource
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 5,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
}
]
}
]
},
"runAfter": {},
"type": "Compose"
},
"Compose_3": {
"inputs": "#variables('Qty')",
"runAfter": {
"Until": [
"Succeeded"
]
},
"type": "Compose"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "temp",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "Qty",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"Release": {
"items": {
"properties": {
"O_Id": {
"type": "string"
},
"R_ID": {
"type": "string"
},
"Res": {
"items": {
"properties": {
"A_Id": {
"type": "string"
},
"F_Qty": {
"type": "integer"
},
"I_Id": {
"type": "string"
},
"OL_Id": {
"type": "string"
},
"Qty": {
"type": "integer"
},
"RL_Id": {
"type": "string"
},
"Unique_Identifier": {
"type": "string"
}
},
"required": [
"A_Id",
"F_Qty",
"I_Id",
"OL_Id",
"Qty",
"RL_Id",
"Unique_Identifier"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"O_Id",
"R_ID",
"Res"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Until": {
"actions": {
"Condition": {
"actions": {
"Compose_2": {
"inputs": "#add(outputs('Compose_4'),variables('Qty'))",
"runAfter": {
"Compose_4": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_4": {
"inputs": "#add(body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['Qty'],body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['Qty'])",
"runAfter": {},
"type": "Compose"
},
"Set_variable": {
"inputs": {
"name": "Qty",
"value": "#outputs('Compose_2')"
},
"runAfter": {
"Compose_2": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": {
"and": [
{
"equals": [
"#body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['I_Id']",
"#body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['I_Id']"
]
}
]
},
"runAfter": {},
"type": "If"
},
"Increment_variable": {
"inputs": {
"name": "temp",
"value": 1
},
"runAfter": {
"Condition": [
"Succeeded"
]
},
"type": "IncrementVariable"
}
},
"expression": "#equals(variables('temp'), length(body('Parse_JSON')?['Release']?[0]?['Res']))",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Parse JSON with map of list

I am new to scala and JSON parsing and need some help. I need to parse the complex JSON (below) to get the values of "name" in "dimension" key i.e I need PLATFORM and OS_VERSION.
I tried multiple options, but it is not working. Any help is appreciated
This is a snippet of the code I tried, but I am not able to proceed further in parsing the list. I believe the 'ANY' keyword is causing some mismatch / issues.
import org.json4s._
import org.json4s.jackson.JsonMethods._
implicit val formats = org.json4s.DefaultFormats
val mapJSON = parse(tmp).extract[Map[String, Any]]
println(mapJSON)
//for ((k,v) <- mapJSON) printf("key: %s, value: %s\n", k, v)
val list_map = mapJSON("dimensions")
{
"uuid": "uuidddd",
"last_modified": 1559080222953,
"version": "2.6.1.0",
"name": "FULL_DAY_2_mand_date",
"is_draft": false,
"model_name": "FULL_DAY_1_may05",
"description": "",
"null_string": null,
"dimensions": [
{
"name": "PLATFORM",
"table": "tbl1",
"column": "PLATFORM",
"derived": null
},
{
"name": "OS_VERSION",
"table": "tbl1",
"column": "OS_VERSION",
"derived": null
},
],
"measures": [
{
"name": "_COUNT_",
"function": {
"expression": "COUNT",
"parameter": {
"type": "constant",
"value": "1"
},
"returntype": "bigint"
}
},
{
"name": "UU",
"function": {
"expression": "COUNT_DISTINCT",
"parameter": {
"type": "column",
"value": "tbl1.USER_ID"
},
"returntype": "hllc(12)"
}
},
{
"name": "CONT_SIZE",
"function": {
"expression": "SUM",
"parameter": {
"type": "column",
"value": "tbl1.SIZE"
},
"returntype": "bigint"
}
},
{
"name": "CONT_COUNT",
"function": {
"expression": "SUM",
"parameter": {
"type": "column",
"value": "tbl1.COUNT"
},
"returntype": "bigint"
}
}
],
"dictionaries": [],
"rowkey": {
"rowkey_columns": [
{
"column": "tbl1.OS_VERSION",
"encoding": "dict",
"encoding_version": 1,
"isShardBy": false
},
{
"column": "tbl1.PLATFORM",
"encoding": "dict",
"encoding_version": 1,
"isShardBy": false
},
{
"column": "tbl1.DEVICE_FAMILY",
"encoding": "dict",
"encoding_version": 1,
"isShardBy": false
}
]
},
"hbase_mapping": {
"column_family": [
{
"name": "F1",
"columns": [
{
"qualifier": "M",
"measure_refs": [
"_COUNT_",
"CONT_SIZE",
"CONT_COUNT"
]
}
]
},
{
"name": "F2",
"columns": [
{
"qualifier": "M",
"measure_refs": [
"UU"
]
}
]
}
]
},
"aggregation_groups": [
{
"includes": [
"tbl1.PLATFORM",
"tbl1.OS_VERSION"
],
"select_rule": {
"hierarchy_dims": [],
"mandatory_dims": [
"tbl1.DATE_HR"
],
"joint_dims": []
}
}
],
"signature": "ttrrs==",
"notify_list": [],
"status_need_notify": [
"ERROR",
"DISCARDED",
"SUCCEED"
],
"partition_date_start": 0,
"partition_date_end": 3153600000000,
"auto_merge_time_ranges": [
604800000,
2419200000
],
"volatile_range": 0,
"retention_range": 0,
"engine_type": 4,
"storage_type": 2,
"override_kylin_properties": {
"job.queuename": "root.production.P0",
"is-mandatory-only-valid": "true"
},
"cuboid_black_list": [],
"parent_forward": 3,
"mandatory_dimension_set_list": [],
"snapshot_table_desc_list": []
}
You need to make more specific classes for parsing the data, something like this:
case class Dimension(name: String, table: String, column: String)
case class AllData(uuid: String, dimensions: List[Dimension])
val data = parse(tmp).extract[AllData]
val names = data.dimensions.map(_.name)

Couchbase N1QL query really slow

I'm working on a project where we use Couchbase 4.1 and we are trying to use N1QL to query for documents. Problem is that it seems very slow even though I have created indexees. The query takes around ~2 seconds with ~11000 documents.
The query:
SELECT name, displayName, imageId, childCategories FROM `bd-couchbase` WHERE assortment = 'CategoryAssortmentOne' AND categoryPath = 'category-displayname/subcategory-displayName' AND displayName IS NOT MISSING
My document is looking like this:
{
"parentName": "8442",
"categoryPath": "category-displayname/subcategory-displayName",
"lastUpdated": "2016-05-31T11:02:03.5129252+02:00",
"childCategories": [
{
"name": "0041",
"displayName": "Category 1",
"imageId": "0041"
},
{
"name": "0042",
"displayName": "Category 2",
"imageId": "0042"
},
{
"name": "0043",
"displayName": "Category 3",
"imageId": "0043"
},
{
"name": "0044",
"displayName": "Category 4",
"imageId": "0044"
},
{
"name": "0045",
"displayName": "Category 5",
"imageId": "0045"
},
{
"name": "0046",
"displayName": "Category 6",
"imageId": "0046"
}
],
"assortment": "CategoryAssortmentOne",
"name": "0040",
"displayName": "MyCategory",
"imageId": "0040"
}
I have the following index:
CREATE INDEX `category_idx` ON `bd-couchbase`((meta().`id`),`name`,`displayName`,`imageId`,`categoryPath`,`childCategories`,`assortment`) USING GSI;
When I execute the explain I can see it uses the #primary index and then doing a fetch (which I guess is the slow part of the query). But when I have created my index is not then supposed to use that?
The result of my explain:
{
"requestID": "da1946f3-5cc8-4d1e-a05b-06789aa6be92",
"signature": "json",
"results": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "my-couchbase",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "my-couchbase",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "((((`my-couchbase`.`assortment`) =
\"CategoryAssortmentOne\") and ((`my-couchbase`.`categoryPath`) = \"category-displayname/subcategory-displayName\")) and ((`my-couchbase`.`displayName`) is not missing))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "(`my-couchbase`.`name`)"
},
{
"expr": "(`my-couchbase`.`displayName`)"
},
{
"expr": "(`my-couchbase`.`imageId`)"
},
{
"expr": "(`my-couchbase`.`childCategorie
s`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
],
"status": "success",
"metrics": {
"elapsedTime": "13.6696ms",
"executionTime": "13.6696ms",
"resultCount": 1,
"resultSize": 2089
}
}
Any suggestions?
Thanks in advance.
the query service didn't seem to be able to match your index with the query. any particular reason you included the meta.id in the index?
try redefining the index to cover only the fields used in your WHERE clause: assortment, categoryPath and displayName, and see if it gets mentioned in the EXPLAIN after that.
CREATE INDEX category_idx ON `bd-couchbase`(assortment, categoryPath, displayName, imageId, childCategories, name);

Couchbase order by retuning null results

I'm querying my database using N1QL this way:
SELECT sum(l.lo_revenue) as revenue, o.d_year, p.p_brand1 from (SELECT p_brand1, lineorder from part where p_brand1='MFGR#2221') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o
where s.s_region='EUROPE'
group by o.d_year, p.p_brand1
order by o.d_year, p.p_brand1
limit 5;
But it returns revenue: null
If I query without order by it gives me the right answer but unsorted, like this:
SELECT sum(l.lo_revenue) as revenue, o.d_year, p.p_brand1 from (SELECT p_brand1, lineorder from part where p_brand1='MFGR#2221') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o
where s.s_region='EUROPE'
group by o.d_year, p.p_brand1
order by o.d_year, p.p_brand1
limit 5;
I can query this way too, having the right answer, sorted:
SELECT SUM(l.lo_revenue), o.d_year, p.p_brand1
from part p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o
where p.p_brand1='MFGR#2221' and s.s_region='EUROPE'
group by o.d_year, p.p_brand1
order by o.d_year, p.p_brand1;
But it takes a lot of time and I would like to filter the documents before UNNEST, insted of UNNEST all documents. Is it a bug, or I'm doing something wrong?
My data is like this:
{
"p_partkey": 1,
"p_name": "lace spring",
"p_mfgr": "MFGR#1",
"p_category": "MFGR#11",
"p_brand1": "MFGR#1121",
"p_color": "goldenrod",
"p_type": "PROMO BURNISHED COPPER",
"p_size": 7,
"p_container": "JUMBO PKG",
"lineorder": [{
"lo_orderkey": 504065,
"lo_linenumber": 6,
"lo_custkey": 14704,
"lo_partkey": 1,
"lo_suppkey": 557,
"lo_orderdate": 19920603,
"lo_orderpriority": "5-LOW",
"lo_shippriority": "0",
"lo_quantity": 49,
"lo_extendedprice": 4414900,
"lo_ordtotalprice": 26849571,
"lo_discount": 3,
"lo_revenue": 4282453,
"lo_supplycost": 54060,
"lo_tax": 0,
"lo_commitdate": 19920712,
"lo_shipmode": "RAIL",
"orderdate": [{
"d_datekey": 19920603,
"d_date": "June 3, 1992",
"d_dayofweek": "Thursday",
"d_month": "June",
"d_year": 1992,
"d_yearmonthnum": 199206,
"d_yearmonth": "jun\/92",
"d_daynuminweek": 5,
"d_daynuminmonth": 3,
"d_daynuminyear": 155,
"d_monthnuminyear": 6,
"d_weeknuminyear": 23,
"d_sellingseason": "Summer",
"d_lastdayinweekfl": false,
"d_lastdayinmonthfl": true,
"d_holidayfl": false,
"d_weekdayfl": true
}],
"commitdate": [{
"d_datekey": 19920712,
"d_date": "July 12, 1992",
"d_dayofweek": "Monday",
"d_month": "July",
"d_year": 1992,
"d_yearmonthnum": 199207,
"d_yearmonth": "jul\/92",
"d_daynuminweek": 2,
"d_daynuminmonth": 12,
"d_daynuminyear": 194,
"d_monthnuminyear": 7,
"d_weeknuminyear": 28,
"d_sellingseason": "Summer",
"d_lastdayinweekfl": false,
"d_lastdayinmonthfl": true,
"d_holidayfl": false,
"d_weekdayfl": true
}],
"customer": [{
"c_custkey": 14704,
"c_name": "Customer#000014704",
"c_address": "uZaxFV8o9IGgayUEWtPU1Xmw",
"c_city": "JORDAN 5",
"c_nation": "JORDAN",
"c_region": "MIDDLE EAST",
"c_phone": "23-688-772-4209",
"c_mktsegment": "BUILDING"
}],
"supplier": [{
"s_suppkey": 557,
"s_name": "Supplier#000000557",
"s_address": "jj0wUYh9K3fG5Jh",
"s_city": "CANADA 5",
"s_nation": "CANADA",
"s_region": "AMERICA",
"s_phone": "13-390-153-6699"
}]
}, {
"lo_orderkey": ...}
This is the output of the explain, it shows the order by function, but it returns null:
{
"requestID": "654ee29a-69b9-437a-9f0e-242ac936b4f7",
"signature": "json",
"results": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "part",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "part",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "((`part`.`p_brand1`) = \"MFGR#1121\")"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "(`part`.`p_brand1`)"
},
{
"expr": "(`part`.`lineorder`)"
}
]
}
]
}
}
]
},
{
"#operator": "Alias",
"as": "p"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Unnest",
"as": "l",
"expr": "(`p`.`lineorder`)"
},
{
"#operator": "Unnest",
"as": "s",
"expr": "(`l`.`supplier`)"
},
{
"#operator": "Unnest",
"as": "o",
"expr": "(`l`.`orderdate`)"
},
{
"#operator": "Filter",
"condition": "((`s`.`s_region`) = \"AMERICA\")"
},
{
"#operator": "InitialGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
}
]
}
},
{
"#operator": "IntermediateGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
},
{
"#operator": "FinalGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "InitialProject",
"result_terms": [
{
"as": "revenue",
"expr": "sum((`l`.`lo_revenue`))"
},
{
"as": "year",
"expr": "(`o`.`d_year`)"
},
{
"as": "p_brand1",
"expr": "(`p`.`p_brand1`)"
}
]
}
]
}
}
]
},
{
"#operator": "Order",
"sort_terms": [
{
"expr": "(`o`.`d_year`)"
},
{
"expr": "(`p`.`p_brand1`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
],
"status": "success",
"metrics": {
"elapsedTime": "8.921246ms",
"executionTime": "8.838345ms",
"resultCount": 1,
"resultSize": 6915
}
}
Follows the EXPLAIN without order by:
cbq> EXPLAIN
> {CT SUM(l.lo_revenue) as revenue, o.d_year as year, p.p_brand1 as p_brand1
> {1121') as p UNNEST p.lineorder l UNNEST l.supplier s UNNEST l.orderdate o
> where s.s_region='AMERICA'
> group by o.d_year, p.p_brand1
> ;
{
"requestID": "160cbad9-1d32-4d67-9c94-1623bba27d51",
"signature": "json",
"results": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "part",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "part",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "((`part`.`p_brand1`) = \"MFGR#1121\")"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "(`part`.`p_brand1`)"
},
{
"expr": "(`part`.`lineorder`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
},
{
"#operator": "Alias",
"as": "p"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Unnest",
"as": "l",
"expr": "(`p`.`lineorder`)"
},
{
"#operator": "Unnest",
"as": "s",
"expr": "(`l`.`supplier`)"
},
{
"#operator": "Unnest",
"as": "o",
"expr": "(`l`.`orderdate`)"
},
{
"#operator": "Filter",
"condition": "((`s`.`s_region`) = \"AMERICA\")"
},
{
"#operator": "InitialGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
}
]
}
},
{
"#operator": "IntermediateGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
},
{
"#operator": "FinalGroup",
"aggregates": [
"sum((`l`.`lo_revenue`))"
],
"group_keys": [
"(`o`.`d_year`)",
"(`p`.`p_brand1`)"
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "InitialProject",
"result_terms": [
{
"as": "revenue",
"expr": "sum((`l`.`lo_revenue`))"
},
{
"as": "year",
"expr": "(`o`.`d_year`)"
},
{
"as": "p_brand1",
"expr": "(`p`.`p_brand1`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
],
"status": "success",
"metrics": {
"elapsedTime": "10.661133ms",
"executionTime": "10.575926ms",
"resultCount": 1,
"resultSize": 5600
}
}
FinalProject is missing on sub query. Fix will be included in upcoming 4.5 Beta.