@@ -11,7 +11,7 @@ import cronParser from 'cron-parser';
1111
1212import moment from 'moment-timezone' ;
1313import inflection from 'inflection' ;
14- import { FROM_PARTITION_RANGE , inDbTimeZone , MAX_SOURCE_ROW_LIMIT , QueryAlias , getEnv } from '@cubejs-backend/shared' ;
14+ import { FROM_PARTITION_RANGE , inDbTimeZone , MAX_SOURCE_ROW_LIMIT , QueryAlias , getEnv , timeSeries } from '@cubejs-backend/shared' ;
1515
1616import {
1717 buildSqlAndParams as nativeBuildSqlAndParams ,
@@ -576,6 +576,29 @@ export class BaseQuery {
576576 return false ;
577577 }
578578
579+ buildSqlAndParamsTest ( exportAnnotatedSql ) {
580+ if ( ! this . options . preAggregationQuery && ! this . options . disableExternalPreAggregations && this . externalQueryClass ) {
581+ if ( this . externalPreAggregationQuery ( ) ) { // TODO performance
582+ return this . externalQuery ( ) . buildSqlAndParams ( exportAnnotatedSql ) ;
583+ }
584+ }
585+ const js_res = this . compilers . compiler . withQuery (
586+ this ,
587+ ( ) => this . cacheValue (
588+ [ 'buildSqlAndParams' , exportAnnotatedSql ] ,
589+ ( ) => this . paramAllocator . buildSqlAndParams (
590+ this . buildParamAnnotatedSql ( ) ,
591+ exportAnnotatedSql ,
592+ this . shouldReuseParams
593+ ) ,
594+ { cache : this . queryCache }
595+ )
596+ ) ;
597+ const rust = this . buildSqlAndParamsRust ( exportAnnotatedSql ) ;
598+ console . log ( 'js result: ' , js_res [ 0 ] ) ;
599+ console . log ( 'rust result: ' , rust [ 0 ] ) ;
600+ return js_res ;
601+ }
579602 /**
580603 * Returns an array of SQL query strings for the query.
581604 * @param {boolean } [exportAnnotatedSql] - returns annotated sql with not rendered params if true
@@ -628,6 +651,10 @@ export class BaseQuery {
628651 return res ;
629652 }
630653
654+ //FIXME helper for native generator, maybe should be moved entire to rust
655+ generateTimeSeries ( granularity , dateRange ) {
656+ return timeSeries ( granularity , dateRange ) ;
657+ }
631658 get shouldReuseParams ( ) {
632659 return false ;
633660 }
@@ -1381,6 +1408,7 @@ export class BaseQuery {
13811408 ) || undefined
13821409 ) ;
13831410 const baseQueryAlias = this . cubeAlias ( 'base' ) ;
1411+ console . log ( "!!! date join contdition: " , dateJoinCondition ) ;
13841412 const dateJoinConditionSql =
13851413 dateJoinCondition . map (
13861414 ( [ d , f ] ) => f (
@@ -1392,6 +1420,8 @@ export class BaseQuery {
13921420 )
13931421 ) . join ( ' AND ' ) ;
13941422
1423+ console . log ( "!!! date join contdition sql: " , dateJoinConditionSql ) ;
1424+
13951425 return this . overTimeSeriesSelect (
13961426 cumulativeMeasures ,
13971427 dateSeriesSql ,
@@ -3231,7 +3261,16 @@ export class BaseQuery {
32313261 '{% if offset is not none %}\nOFFSET {{ offset }}{% endif %}' ,
32323262 group_by_exprs : '{{ group_by | map(attribute=\'index\') | join(\', \') }}' ,
32333263 join : '{{ join_type }} JOIN {{ source }} ON {{ condition }}' ,
3234- cte : '{{ alias }} AS ({{ query | indent(2, true) }})'
3264+ cte : '{{ alias }} AS ({{ query | indent(2, true) }})' ,
3265+ time_seria_select : 'SELECT date_from::timestamp AS "date_from",\n' +
3266+ 'date_to::timestamp AS "date_to" \n' +
3267+ 'FROM(\n' +
3268+ ' VALUES ' +
3269+ '{% for time_item in seria %}' +
3270+ '(\'{{ time_item | join(\'\\\', \\\'\') }}\')' +
3271+ '{% if not loop.last %}, {% endif %}' +
3272+ '{% endfor %}' +
3273+ ') AS dates (date_from, date_to)'
32353274 } ,
32363275 expressions : {
32373276 column_reference : '{% if table_name %}{{ table_name }}.{% endif %}{{ name }}' ,
0 commit comments