PykQuery 1.0.0 Documentation - pykih PykQuery 1.0.0 Documentation | pykih Humane ClubMade in Humane Club
table of contents

PykQuery 1.0.0 Documentation

This is the main class to create a query.  All the PykQuery functions sets the configuration of the query. The run() function will actually execute the query and return the resultant dataset. This will create a PykQuery instance which will have all the SQL functions which can be performed on the data.

var query = new pykQuery();

Instance Members

 bin(options)

This function selects the distinct columns that you want to display in the result.

bin(options: Object): object

Parameters

options(Object) Options that are passed to the bin function

Name Description
options.x string Name of the column to bin
options.type string? Set this value to “date” to consider a value as a date
options.bins Number? Set this value to a number to force the number of bins to be a value. Default: 5

Returns

object: this – Instance of pykQuery

distinct()

This function selects the distinct columns that you want to display in the result.

distinct(): object

Returns

object: this – Instance of pykQuery

Throws

  • IncorrectArgument: Throws incorrect argument error if arguments are not specified correctly

This will throw an error as distinct function does not accept values

new pykQuery()
  .select("ga:country","ga:hostname")
  .distinct("ga:sourceMedium")
  .from(data)
  .run();

group(groupObject)

This function selects the columns that you want to aggregate by specifying the aggregation function to be applied.

group(groupObject: ...Object): object

Parameters

groupObject(...Object) The object containing metric information

Name Description
groupObject.column string The name of the column.
groupObject.aggregationstring The aggregation function name. Supported aggregate functions are “sum”, “count”, “min”, “max”, “avg”.
groupObject.alias string? The alias for result

Returns

object: query – Object which contains chaining methods.

Throws

  • IncorrectArgument: Throws incorrect argument error if arguments are not specified correctly

Example

This will calculate the sum of “ga:exitRate”

new pykQuery()
  .select({
      column:"ga:country",
      alias: "country"
  },
  {
      column:"ga:hostname",
      alias: "host"
  })
  .group({
      column:"ga:exitRate",
      aggregation:"sum"
  })
  .groupBy()
  .from(data)
  .run();
// The query output
[{
   "country": "Armenia",
   "host": "www.fusioncharts.com",
   "sum of ga:exitRate": 100
}, {
   "country": "Austria",
   "host": "www.fusioncharts.com",
   "sum of ga:exitRate": 200
}, {
   "country": "China",
   "host": "www.fusioncharts.com",
   "sum of ga:exitRate": 0
}]

groupBy()

This function is used to aggregate the data by grouping on the specified columns. If called without the column names, it will automatically apply grouping on the column names passed in the select function. You can also specify extra columns to group the data on which are not specified in the select function.

groupBy(): object

Returns

object: this – Instance of pykQuery.

Throws

  • IncorrectArgument: Throws incorrect argument error if arguments are not specified correctly.

Example

This will simply groupBy all the columns that you have passed in select clause

new pykQuery()
  .select({
      column:"ga:country",
      alias: "country"
  },
  {
      column:"ga:hostname",
      alias: "host"
  })
  .groupBy()
  .from(data)
  .run();
// The query result:
[{
   "country": "Armenia",
   "host": "www.fusioncharts.com"
}, {
   "country": "Austria",
   "host": "www.fusioncharts.com"
}, {
   "country": "China",
   "host": "www.fusioncharts.com"
}]