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

Structured queries #848

Merged
merged 8 commits into from
Apr 13, 2017
Merged

Structured queries #848

merged 8 commits into from
Apr 13, 2017

Conversation

goller
Copy link
Contributor

@goller goller commented Feb 6, 2017

  • CHANGELOG.md updated
  • Rebased/mergable
  • Tests pass
  • Sign CLA (if not already signed)

Connect #824

The problem

The current QueryConfig object is not able to represent InfluxQL.
Not simple to convert InfluxQL to QueryConfigs

The Solution

This PR creates /chonograf/v1/sources/:id/queries endpoint to analyze queries and give back meta database about 'em.

The routes link is available from links.queries in the source object.

The endpoint only accepts POST of the following JSON structure:

{
	"queries": [
		{
			"query": ""
		}
	]
}

and responds with:

{
  "queries": [
    {
      		"query": "",
     	 	"queryConfig": {},
     		 "queryAST": {}
		}
	]
}

The response is in the same order as the request. query in response is identical to the request.
queryConfig will always be present and either initialized with rawText if the query is not parsable, or null.

queryAST is present or not if the query can be represented with the AST.

Examples:

{
	"queries": [
		{
			"query": 	"SELECT usage_idle from telegraf.autogen.cpu"
		},
		{
			"query": 	"SELECT howdy from telegraf.autogen.doody"
		},
		{
			"query": 	"SHOW MEASUREMENTS"
		}
	]
}

It will respond with the following:

{
  "queries": [
    {
      "query": "SELECT usage_idle from telegraf.autogen.cpu",
      "queryConfig": {
        "database": "telegraf",
        "measurement": "cpu",
        "retentionPolicy": "autogen",
        "fields": [
          {
            "field": "usage_idle",
            "funcs": []
          }
        ],
        "tags": {},
        "groupBy": {
          "time": "",
          "tags": []
        },
        "areTagsAccepted": false,
        "rawText": null
      },
      "queryAST": {
        "fields": [
          {
            "column": {
              "expr": "reference",
              "val": "usage_idle"
            }
          }
        ],
        "sources": [
          {
            "database": "telegraf",
            "retentionPolicy": "autogen",
            "name": "cpu",
            "type": "measurement"
          }
        ]
      }
    },
    {
      "query": "SELECT howdy from telegraf.autogen.doody",
      "queryConfig": {
        "database": "telegraf",
        "measurement": "doody",
        "retentionPolicy": "autogen",
        "fields": [
          {
            "field": "howdy",
            "funcs": []
          }
        ],
        "tags": {},
        "groupBy": {
          "time": "",
          "tags": []
        },
        "areTagsAccepted": false,
        "rawText": null
      },
      "queryAST": {
        "fields": [
          {
            "column": {
              "expr": "reference",
              "val": "howdy"
            }
          }
        ],
        "sources": [
          {
            "database": "telegraf",
            "retentionPolicy": "autogen",
            "name": "doody",
            "type": "measurement"
          }
        ]
      }
    },
    {
      "query": "SHOW MEASUREMENTS",
      "queryConfig": {
        "database": "",
        "measurement": "",
        "retentionPolicy": "",
        "fields": [],
        "tags": {},
        "groupBy": {
          "time": "",
          "tags": []
        },
        "areTagsAccepted": false,
        "rawText": "SHOW MEASUREMENTS"
      }
    }
  ]
}

@goller goller force-pushed the feature/structured-queries branch from d3c8564 to 84e9e00 Compare April 7, 2017 21:59
@goller goller changed the title WIP structured queries Structured queries Apr 7, 2017
@121watts 121watts merged commit 65231c2 into master Apr 13, 2017
@goller goller deleted the feature/structured-queries branch May 19, 2017 21:11
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

Successfully merging this pull request may close these issues.

3 participants