Skip to content

Commit

Permalink
parquest field
Browse files Browse the repository at this point in the history
  • Loading branch information
zabkwak committed Mar 22, 2022
1 parent 969cc7e commit 0bfdaa7
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 2 deletions.
125 changes: 125 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mat-utils",
"version": "0.1.0",
"version": "0.2.0",
"description": "Utils for Media analytics tool",
"main": "index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -46,14 +46,19 @@
"@types/core-js": "^2.5.5",
"@types/mocha": "^9.1.0",
"@types/node": "^12.20.47",
"@types/parquetjs": "^0.10.3",
"chai": "^4.3.6",
"dotenv": "^16.0.0",
"mocha": "^9.2.2",
"parquetjs": "^0.11.2",
"run-script-os-fix": "^1.0.4",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"tslint": "^6.1.3",
"typedoc": "^0.22.13",
"typescript": "^4.6.2"
},
"peerDependencies": {
"parquetjs": "^0.11.2"
}
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CSV from './csv';
import Logger from './logger';
import ParquetField from './parquet/field';

const sleep = (timeout: number) => {
return new Promise((resolve) => {
Expand All @@ -10,5 +11,6 @@ const sleep = (timeout: number) => {
export {
CSV,
Logger,
ParquetField,
sleep,
};
71 changes: 71 additions & 0 deletions src/parquet/field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
interface IMapField {
fields: Record<string, Field>;
repeated: boolean;
optional: boolean;
}

export default class Field {

// #region Types

public static get string() {
return new this('UTF8');
}

public static get integer() {
return new this('INT64');
}

public static get float() {
return new this('DOUBLE');
}

public static get timestamp() {
return new this('TIMESTAMP_MILLIS');
}

public static get boolean() {
return new this('BOOLEAN');
}

public static get date() {
return new this('DATE');
}

public static arrayOf(type: Field): Field {
const f = new this(type.type);
f.array();
return f;
}

public static map(fields: Record<string, Field>, array: boolean = false): IMapField {
return {
fields,
repeated: array,
optional: true,
};
}

// #endregion

public type: string;

public optional: boolean = true;

public repeated: boolean = false;

constructor(type: string) {
this.type = type;
this.optional = true;
}

public required(): this {
this.optional = false;
return this;
}

public array(): this {
this.repeated = true;
return this;
}
}

0 comments on commit 0bfdaa7

Please sign in to comment.