-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev' into dev
- Loading branch information
Showing
13 changed files
with
940 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/ingestion/cqube-spec-checker/dimension.data.validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export class DimensionDataValidator { | ||
grammarContent: any; | ||
lines: any; | ||
pkIndexLine: any; | ||
dataTypesLine: any; | ||
headerLine: any; | ||
dataContent: any; | ||
dataContentLines: any; | ||
errors: any[]; | ||
constructor(grammarContent, dataContent) { | ||
this.grammarContent = grammarContent; | ||
this.lines = this.grammarContent.trim().split('\n'); | ||
this.pkIndexLine = this.lines[0].trim().split(','); | ||
this.dataTypesLine = this.lines[1].trim().split(','); | ||
this.headerLine = this.lines[2].trim().split(','); | ||
this.dataContent = dataContent; | ||
this.dataContentLines = this.dataContent | ||
.trim() | ||
.split('\n')[0] | ||
.trim() | ||
.split(','); | ||
this.errors = []; | ||
} | ||
|
||
verify() { | ||
this.verifyColumnsToGrammar(); | ||
return this.errors; | ||
} | ||
|
||
verifyColumnsToGrammar() { | ||
this.headerLine.forEach((header, index) => { | ||
this.dataContentLines.indexOf(header) === -1 | ||
? this.errors.push({ | ||
row: 0, | ||
col: index, | ||
errorCode: 1001, | ||
error: `Missing header from grammar file: ${header}`, | ||
}) | ||
: null; | ||
}); | ||
|
||
this.dataContentLines.forEach((header, index) => { | ||
this.headerLine.indexOf(header) === -1 | ||
? this.errors.push({ | ||
row: 0, | ||
col: index, | ||
errorCode: 1001, | ||
error: `Extra header not in grammar file: ${header}`, | ||
data: header, | ||
}) | ||
: null; | ||
}); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/ingestion/cqube-spec-checker/dimension.grammar.validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
export class DimensionValidator { | ||
content: any; | ||
lines: any; | ||
pkIndexLine: any; | ||
dataTypesLine: any; | ||
headerLine: any; | ||
constructor(content) { | ||
this.content = content; | ||
this.lines = this.content.trim().split('\n'); | ||
this.pkIndexLine = this.lines[0].trim().split(','); | ||
this.dataTypesLine = this.lines[1].trim().split(','); | ||
this.headerLine = this.lines[2].trim().split(','); | ||
} | ||
|
||
verify() { | ||
const errors = []; | ||
errors.push(...this.verifyColumns()); | ||
errors.push(...this.verifyPkIndexLine()); | ||
errors.push(...this.verifyDataTypes()); | ||
return errors; | ||
} | ||
|
||
verifyColumns() { | ||
const errors = []; | ||
const columnCount = this.pkIndexLine.length; | ||
this.lines.forEach((line, lineNumber) => { | ||
if (line !== '') { | ||
// Ignore last line | ||
const lineColumns = line.split(',').length; | ||
if (lineColumns !== columnCount) { | ||
errors.push({ | ||
row: lineNumber, | ||
col: 0, | ||
errorCode: 2003, | ||
error: `Line ${lineNumber + 1 | ||
}: Invalid number of columns ${lineColumns} (expected ${columnCount}), ${line.split( | ||
',', | ||
)}`, | ||
data: line, | ||
}); | ||
} | ||
} | ||
}); | ||
return errors; | ||
} | ||
|
||
verifyPkIndexLine() { | ||
const errors = []; | ||
if ( | ||
this.pkIndexLine.indexOf('PK') === -1 || | ||
this.pkIndexLine.indexOf('Index') === -1 | ||
) { | ||
errors.push({ | ||
row: 0, | ||
col: 0, | ||
errorCode: 1003, | ||
error: `Invalid PK/Index: First row must include 'PK' and 'Index' but found "${this.pkIndexLine}"`, | ||
data: this.pkIndexLine, | ||
}); | ||
} | ||
return errors; | ||
} | ||
|
||
verifyDataTypes() { | ||
const errors = []; | ||
this.dataTypesLine.forEach((dataType, columnIndex) => { | ||
if (dataType !== 'string' && dataType !== 'integer') { | ||
errors.push({ | ||
row: 1, | ||
col: columnIndex, | ||
errorCode: 1002, | ||
error: `Invalid data type at column ${columnIndex + 1 | ||
}: Only 'string' and 'integer' are allowed but found '${dataType}'`, | ||
data: this.dataTypesLine, | ||
}); | ||
} | ||
}); | ||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type ValidationErrors = { | ||
row: string | number; | ||
col: string | number; | ||
errorCode: number; | ||
error: string; | ||
data?: any; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export enum FileType { | ||
DimensionGrammar = 'dimension-grammar', | ||
DimensionData = 'dimension-data', | ||
EventGrammar = 'event-grammar', | ||
EventData = 'event-data', | ||
} | ||
|
||
export class FileValidateRequest { | ||
type: FileType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ValidationErrors } from './errors'; | ||
|
||
export class SingleFileValidationResponse { | ||
errors: ValidationErrors[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.