@@ -26,7 +26,7 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
2626 private logger = this . getLogger ( ) ;
2727 protected poolMapping = new Map <
2828 string ,
29- { pool : Pool ; options ?: PGOptions }
29+ { pool : Pool ; options ?: PGOptions ; properties ?: Record < string , any > }
3030 > ( ) ;
3131 protected UserPool = new Map < string , Pool > ( ) ;
3232
@@ -52,6 +52,7 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
5252 this . poolMapping . set ( profile . name , {
5353 pool,
5454 options : profile . connection ,
55+ properties : profile . properties ,
5556 } ) ;
5657 this . logger . debug ( `Profile ${ profile . name } initialized` ) ;
5758 }
@@ -61,6 +62,7 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
6162 sql,
6263 directory,
6364 profileName,
65+ options : cannerOptions ,
6466 } : ExportOptions ) : Promise < void > {
6567 if ( ! this . poolMapping . has ( profileName ) ) {
6668 throw new InternalError ( `Profile instance ${ profileName } not found` ) ;
@@ -69,12 +71,16 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
6971 if ( ! fs . existsSync ( directory ) ) {
7072 throw new InternalError ( `Directory ${ directory } not found` ) ;
7173 }
72- const { options : connection } = this . poolMapping . get ( profileName ) ! ;
73-
74+ const { options : connection , properties } =
75+ this . poolMapping . get ( profileName ) ! ;
7476 const cannerAdapter = new CannerAdapter ( connection ) ;
7577 try {
7678 this . logger . debug ( 'Send the async query to the Canner Enterprise' ) ;
77- const presignedUrls = await cannerAdapter . createAsyncQueryResultUrls ( sql ) ;
79+ const header = this . getCannerRequestHeader ( properties , cannerOptions ) ;
80+ const presignedUrls = await cannerAdapter . createAsyncQueryResultUrls (
81+ sql ,
82+ header
83+ ) ;
7884 this . logger . debug (
7985 'Start fetching the query result parquet files from URLs'
8086 ) ;
@@ -85,6 +91,21 @@ export class CannerDataSource extends DataSource<any, PGOptions> {
8591 throw error ;
8692 }
8793 }
94+ private getCannerRequestHeader (
95+ properties ?: Record < string , any > ,
96+ cannerOptions ?: any
97+ ) {
98+ const header : Record < string , string > = { } ;
99+ const userId = cannerOptions ?. userId ;
100+ const rootUserId = properties ?. [ 'rootUserId' ] ;
101+ if ( userId && rootUserId ) {
102+ header [
103+ 'x-trino-session'
104+ ] = `root_user_id=${ rootUserId } , canner_user_id=${ userId } ` ;
105+ this . logger . debug ( `Impersonate used: ${ userId } ` ) ;
106+ }
107+ return header ;
108+ }
88109
89110 private async downloadFiles ( urls : string [ ] , directory : string ) {
90111 await Promise . all (
0 commit comments