Merge pull request #987 from theseyi/dataset-path

fix dataset path conversion
This commit is contained in:
Seyi Adebajo 2018-02-21 18:29:31 -08:00 committed by GitHub
commit 364ca7d08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import { assert } from '@ember/debug';
import { DatasetPlatform } from 'wherehows-web/constants';
/**
* Matches a url string with a `urn` query. urn query with letters or underscore segment of any length greater
@ -62,11 +63,23 @@ const getPlatformFromUrn = (candidateUrn: string) => {
*/
const convertWhUrnToLiUrn = (whUrn: string): string => {
assert(`Expected ${whUrn} to be in the WH urn format`, isWhUrn(whUrn));
const [, platform, path] = datasetUrnRegexWH.exec(whUrn)!;
return `urn:li:dataset:(urn:li:dataPlatform:${platform},${path},PROD)`;
const [, platform, path] = datasetUrnRegexWH.exec(whUrn)!;
const formattedPath = convertWhDatasetPathToLiPath(<DatasetPlatform>platform, path);
return `urn:li:dataset:(urn:li:dataPlatform:${platform},${formattedPath},PROD)`;
};
/**
* Converts a path from WH urn format, replace forward slash with periods in non DatasetPlatform.HDFS cases,
* add leading forward slash if platform is DatasetPlatform.HDFS
* @param {DatasetPlatform} platform
* @param {string} path
* @return {string}
*/
const convertWhDatasetPathToLiPath = (platform: DatasetPlatform, path: string): string =>
platform === DatasetPlatform.HDFS ? `/${path}` : path.replace(/\//g, '.');
/**
* Cached RegExp object for a global search of /
* @type {RegExp}