Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following api. functions are available:

...

Code Block
languagegroovy
def ctx = api.getDatamartContext()
def dm = ctx.getDatamart("TransactionsDM")
def ds = ctx.getDataSource("ForecastDS")
def t1 = ctx.newQuery(dm)
t1.select("ProductID", "product")
t1.select("SUM(InvoicePrice)", "revenue")
t1.select("SUM(Quantity)", "volume")

def t2 = ctx.newQuery(ds, false)
t1t2.select("ProductID", "product")
t2.select("Revenue, "revenue")
t2.select("Volume", "volume")
 
def sql = """ 
			SELECT T1.product, T1.revenue AS ActualRevenue, T2.revenue AS ForecastRevenue
				T1.volume AS ActualVolume, T2.volume AS ForecastVolume
				FROM T1 LEFT OUTER JOIN T2 USING (product) 
"""
return ctx.executeSqlQuery(sql, t1, t2)?.toResultMatrix()		// first source gets default alias T1, 2nd gets T2 etc.

(info) For the executeSqlQuery function, the supported SQL syntax depends on the database server of Analytics where typically PostgreSQL 10+ or Greenplum 5.12+ are used.