Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maha Validate query request before actually query #635

Open
YixianNiu opened this issue May 11, 2020 · 2 comments
Open

Maha Validate query request before actually query #635

YixianNiu opened this issue May 11, 2020 · 2 comments

Comments

@YixianNiu
Copy link

YixianNiu commented May 11, 2020

Hi,
We are making a API endpoint which checks whether a request query to maha is valid or not. The query looks like this:
`{
"cube":"fake_cube",
"selectFields":[
{
"field":"fake ID"
}
],
"filterExpressions":[
{
fake filter
},

],
"sortBy":[
{
"field":"fake Id",
"order":"Desc"
}
],
"rowsPerPage":10
}`

We want to check whether the field, cube , filter etc are right. Is there any method that can validate the request before process the query?
Thanks!

@YixianNiu YixianNiu reopened this May 11, 2020
@pranavbhole
Copy link
Contributor

Hello @YixianNiu
take look at the test at com/yahoo/maha/core/query/oracle/OracleQueryGeneratorTest.scala. All you can do is DeSer input request like following and try generating the Request Model for given json. It will return the TRY(Request Model).

val requestOption = ReportingRequest.deserializeSyncWithFactBias(jsonString.getBytes(StandardCharsets.UTF_8), AdvertiserSchema)
val registry = defaultRegistry
val requestModel = RequestModel.from(requestOption.toOption.get, registry)
assert(requestModel.isSuccess, requestModel.errorMessage("Building request model failed"))

test("successfully generate sync force dim driven dim only query with filters and order by and row count") {
val jsonString = s"""{
"cube": "performance_stats",
"selectFields": [
{
"field": "Campaign ID",
"alias": null,
"value": null
},
{
"field": "Ad Group ID",
"alias": null,
"value": null
},
{
"field": "Advertiser Status",
"alias": null,
"value": null
},
{
"field": "Campaign Name",
"alias": null,
"value": null
},
{ "field" : "Source", "value" : "2", "alias" : "Source"}
],
"filterExpressions": [
{"field": "Advertiser ID", "operator": "=", "value": "12345"},
{"field": "Day", "operator": "between", "from": "$fromDate", "to": "$toDate"}
],"sortBy": [
{"field": "Campaign ID", "order": "Asc"}
],
"paginationStartIndex":0,
"rowsPerPage":100,
"forceDimensionDriven": true,
"includeRowCount": true
}"""

val requestOption = ReportingRequest.deserializeSyncWithFactBias(jsonString.getBytes(StandardCharsets.UTF_8), AdvertiserSchema)
val registry = defaultRegistry
val requestModel = RequestModel.from(requestOption.toOption.get, registry)
assert(requestModel.isSuccess, requestModel.errorMessage("Building request model failed"))

val queryPipelineTry = generatePipeline(requestModel.toOption.get)
assert(queryPipelineTry.isSuccess, queryPipelineTry.errorMessage("Fail to get the query pipeline"))

val result =  queryPipelineTry.toOption.get.queryChain.drivingQuery.asInstanceOf[OracleQuery].asString
val expected = """
                 |SELECT  *
                 |      FROM (SELECT ago2.campaign_id "Campaign ID", ago2.id "Ad Group ID", ao0."Advertiser Status" "Advertiser Status", co1.campaign_name "Campaign Name", '2' AS "Source", Count(*) OVER() TOTALROWS, ROWNUM as ROW_NUMBER
                 |            FROM
                 |               ( (SELECT  campaign_id, advertiser_id, id
                 |            FROM ad_group_oracle
                 |            WHERE (advertiser_id = 12345)
                 |            ORDER BY 1 ASC  ) ago2
                 |          INNER JOIN
                 |            (SELECT /*+ CampaignHint */ id, advertiser_id, campaign_name
                 |            FROM campaign_oracle
                 |            WHERE (advertiser_id = 12345)

@YixianNiu
Copy link
Author

Thanks for the info. But why we are using deserializeSyncWithFactBias?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants