-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data generation logic #1
base: master
Are you sure you want to change the base?
Changes from all commits
147b670
d28763d
ba6adad
4259fa5
76306d4
419838e
3fa68ef
727a299
f238772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import DataRow from "./DataRow"; | ||
import TYPES from "./Types"; | ||
import { randomFromArray } from "../helpers"; | ||
|
||
class InitializeError extends Error {} | ||
|
||
/** | ||
* DATABASE_STORAGE_USAGE_HISTORY View | ||
* | ||
* https://docs.snowflake.net/manuals/sql-reference/account-usage/database_storage_usage_history.html | ||
*/ | ||
export default class DatabaseStorageUsageHistory extends DataRow { | ||
constructor(databaseID, databaseName, date) { | ||
super(); | ||
if (!this.constructor._sizes) { | ||
throw new InitializeError( | ||
`Must call ${this.constructor.name}.initialize() first` | ||
); | ||
} | ||
this.USAGE_DATE = date.toISOString(); | ||
this.DATABASE_ID = databaseID; | ||
this.DATABASE_NAME = databaseName; | ||
this._setAverageDatabaseBytes(); | ||
this._setAverageFailsafeBytes(); | ||
} | ||
|
||
_setAverageDatabaseBytes() { | ||
let size = this.constructor._sizes[this.DATABASE_NAME]; | ||
if (Math.random() < 0.1) { | ||
const changeDegree = Math.random() * (0.2 - 0.05) + 0.05; | ||
const change = Math.round(size * changeDegree); | ||
if (Math.random() < 0.3) { | ||
size -= change; | ||
} else { | ||
size += change; | ||
} | ||
} | ||
this.constructor._sizes[this.DATABASE_NAME] = size; | ||
this.AVERAGE_DATABASE_BYTES = size; | ||
} | ||
|
||
_setAverageFailsafeBytes() { | ||
this.AVERAGE_FAILSAFE_BYTES = 0; | ||
if (Math.random() < 0.1) { | ||
this.AVERAGE_FAILSAFE_BYTES = Math.round( | ||
Math.random() * this.AVERAGE_DATABASE_BYTES | ||
); | ||
} | ||
} | ||
|
||
static initialize(dbs) { | ||
if (this._sizes) { | ||
throw new InitializeError( | ||
`Must call ${this.name}.initialize() only once` | ||
); | ||
} | ||
const seedSizes = [1.1e15, 1.2e15, 1.3e15, 1.4e15]; | ||
const sizes = {}; | ||
for (const db of dbs) { | ||
const seed = randomFromArray(seedSizes); | ||
sizes[db.DATABASE_NAME] = Math.round(Math.random() * seed); | ||
} | ||
this._sizes = sizes; | ||
} | ||
|
||
static types() { | ||
return [ | ||
{ | ||
name: "USAGE_DATE", | ||
type: TYPES.timestamp | ||
}, | ||
{ | ||
name: "DATABASE_ID", | ||
type: TYPES.integer | ||
}, | ||
{ | ||
name: "DATABASE_NAME", | ||
type: TYPES.string | ||
}, | ||
{ | ||
name: "AVERAGE_DATABASE_BYTES", | ||
type: TYPES.integer | ||
}, | ||
{ | ||
name: "AVERAGE_FAILSAFE_BYTES", | ||
type: TYPES.integer | ||
} | ||
]; | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import DataRow from "./DataRow"; | ||
import TYPES from "./Types"; | ||
|
||
/** | ||
* DATABASES View | ||
* | ||
* https://docs.snowflake.net/manuals/sql-reference/account-usage/databases.html | ||
*/ | ||
export default class Databases extends DataRow { | ||
constructor(name, id) { | ||
super(); | ||
this.DATABASE_NAME = name; | ||
this.DATABASE_ID = id; | ||
} | ||
|
||
static generate() { | ||
const names = [ | ||
"squiggly_database", | ||
"jims_database", | ||
"jacksonbase", | ||
"prod", | ||
"staging_db", | ||
"dev1" | ||
]; | ||
return names.map((name, idx) => new this(name, idx + 1)); | ||
} | ||
|
||
static types() { | ||
return [ | ||
{ | ||
name: "DATABASE_NAME", | ||
type: TYPES.string | ||
}, | ||
{ | ||
name: "DATABASE_ID", | ||
type: TYPES.integer | ||
} | ||
]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import DataRow from "./DataRow"; | ||
import TYPES from "./Types"; | ||
|
||
const ODDS_NEW = 0.2; | ||
|
||
/** | ||
* LOAD_HISTORY View | ||
* | ||
* https://docs.snowflake.net/manuals/sql-reference/account-usage/load_history.html | ||
*/ | ||
export default class LoadHistory extends DataRow { | ||
constructor(tableID, date) { | ||
super(); | ||
this.TABLE_ID = tableID; | ||
this.LAST_LOAD_TIME = date.toISOString(); | ||
this.ROW_COUNT = Math.round(Math.random() * 100); | ||
this.ERROR_COUNT = Math.random() < 0.1 ? Math.round(Math.random() * 10) : 0; | ||
} | ||
|
||
static oddsNew() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. personally I would define this as a const at the top of the module, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Early on I thought I'd have a lot more "dice rolling" to create an object than I ended up with. So I made this I could set |
||
return ODDS_NEW; | ||
} | ||
|
||
static types() { | ||
return [ | ||
{ | ||
name: "TABLE_ID", | ||
type: TYPES.integer | ||
}, | ||
{ | ||
name: "LAST_LOAD_TIME", | ||
type: TYPES.timestamp | ||
}, | ||
{ | ||
name: "ROW_COUNT", | ||
type: TYPES.integer | ||
}, | ||
{ | ||
name: "ERROR_COUNT", | ||
type: TYPES.integer | ||
} | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import DataRow from "./DataRow"; | ||
import TYPES from "./Types"; | ||
import * as helpers from "../helpers"; | ||
|
||
/** | ||
* LOGIN_HISTORY View | ||
* | ||
* https://docs.snowflake.net/manuals/sql-reference/account-usage/login_history.html | ||
*/ | ||
export default class LoginHistory extends DataRow { | ||
constructor(date) { | ||
super(); | ||
this.EVENT_ID = helpers.getID(); | ||
this.EVENT_TIMESTAMP = date.toISOString(); | ||
const user = helpers.randomFromArray(this.constructor.getUsers()); | ||
this.USER_NAME = user.name; | ||
this.REPORTED_CLIENT_TYPE = user.driver; | ||
this.IS_SUCCESS = Math.random() < 0.9 ? "YES" : "NO"; | ||
} | ||
|
||
static getUsers() { | ||
return [ | ||
{ name: "WEB_CLIENT", driver: "JAVASCRIPT_DRIVER", querySpeed: 1.2 }, | ||
{ name: "BOB", driver: "OTHER", querySpeed: 2.0 }, | ||
{ name: "BI_APP", driver: "JDBC_DRIVER", querySpeed: 0.8 }, | ||
{ name: "JANE", driver: "SNOWFLAKE_UI", querySpeed: 1.0 } | ||
]; | ||
} | ||
|
||
static types() { | ||
return [ | ||
{ | ||
name: "EVENT_ID", | ||
type: TYPES.string | ||
}, | ||
{ | ||
name: "EVENT_TIMESTAMP", | ||
type: TYPES.timestamp | ||
}, | ||
{ | ||
name: "USER_NAME", | ||
type: TYPES.string | ||
}, | ||
{ | ||
name: "REPORTED_CLIENT_TYPE", | ||
type: TYPES.string | ||
}, | ||
{ | ||
name: "IS_SUCCESS", | ||
type: TYPES.string | ||
} | ||
]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍