lightdash ProjectAdapter 接口定义
  TEZNKK3IfmPf 2023年11月12日 48 0

主要介绍接口定义,实际的实现后续说明

ProjectAdapter 是一个比较重要的东西,定义了project 以及dbt client ,WarehouseClient

export interface ProjectAdapter {
compileAllExplores(): Promise<(Explore | ExploreError)[]>;
getDbtPackages(): Promise<DbtPackages | undefined>;
runQuery(sql: string): Promise<Record<string, any>[]>;
test(): Promise<void>;
destroy(): Promise<void>;
}
export interface DbtClient {
installDeps(): Promise<void>;
getDbtManifest(): Promise<DbtRpcGetManifestResults>;
getDbtCatalog(): Promise<DbtRpcDocsGenerateResults>;
getDbtPackages?(): Promise<DbtPackages | undefined>;
test(): Promise<void>;
}

 

export type WarehouseTableSchema = {
[column: string]: DimensionType;
};

 

export type WarehouseCatalog = {
[database: string]: {
[schema: string]: {
[table: string]: WarehouseTableSchema;
};
};
};

 

export interface WarehouseClient {
getCatalog: (
config: {
database: string;
schema: string;
table: string;
columns: string[];
}[],
) => Promise<WarehouseCatalog>;
runQuery(sql: string): Promise<Record<string, any>[]>;
test(): Promise<void>;
}

 

相关实现

packages/backend/src/projectAdapters/projectAdapter.ts

定义实现的入口,从此处也可以看出系统内部的实现

 

export const projectAdapterFromConfig = async (
config: DbtProjectConfig,
warehouseCredentials: CreateWarehouseCredentials,
): Promise<ProjectAdapter> => {
const warehouseClient =
warehouseClientFromCredentials(warehouseCredentials);
const configType = config.type;
Logger.debug(`Initialize project adaptor of type ${configType}`);
switch (config.type) {
case ProjectType.DBT:
return new DbtLocalCredentialsProjectAdapter({
warehouseClient,
projectDir: config.project_dir || '/usr/app/dbt',
warehouseCredentials,
});
case ProjectType.DBT_CLOUD_IDE:
return new DbtCloudIdeProjectAdapter({
warehouseClient,
accountId: `${config.account_id}`,
environmentId: `${config.environment_id}`,
projectId: `${config.project_id}`,
apiKey: config.api_key,
});
case ProjectType.GITHUB:
return new DbtGithubProjectAdapter({
warehouseClient,
githubPersonalAccessToken: config.personal_access_token,
githubRepository: config.repository,
githubBranch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.GITLAB:
return new DbtGitlabProjectAdapter({
warehouseClient,
gitlabPersonalAccessToken: config.personal_access_token,
gitlabRepository: config.repository,
gitlabBranch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.BITBUCKET:
return new DbtBitBucketProjectAdapter({
warehouseClient,
username: config.username,
personalAccessToken: config.personal_access_token,
repository: config.repository,
branch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.AZURE_DEVOPS:
return new DbtAzureDevOpsProjectAdapter({
warehouseClient,
personalAccessToken: config.personal_access_token,
organization: config.organization,
project: config.project,
repository: config.repository,
branch: config.branch,
projectDirectorySubPath: config.project_sub_path,
warehouseCredentials,
});
default:
const never: never = config;
throw new Error(`Adapter not implemented for type: ${configType}`);
}
};

说明

ProjectAdapter 是比较重要的东西,当然lightdash内部还包含了其他东西,比如维度以及度量部分,有些是需要进行编译处理的,后续会介绍下

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月12日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年04月12日   54   0   0 命令git
  TEZNKK3IfmPf   2024年04月19日   64   0   0 git部署
  TEZNKK3IfmPf   2024年05月17日   44   0   0 github
  TEZNKK3IfmPf   2024年04月19日   56   0   0 javagithub
  TEZNKK3IfmPf   2024年04月26日   40   0   0 gitgithub
TEZNKK3IfmPf