Relation

getSchema

Retrieves the schema details for every field in an array format.

Returns:

SchemaArray of fields schema.

     [
{ name: 'Name', type: 'dimension' },
{ name: 'Miles_per_Gallon', type: 'measure', numberFormat: (val) => ${val} miles / gallon },
{ name: 'Cylinder', type: 'dimension' },
{ name: 'Displacement', type: 'measure', defAggFn: 'max' },
{ name: 'HorsePower', type: 'measure', defAggFn: 'max' },
{ name: 'Weight_in_lbs', type: 'measure', defAggFn: 'avg',  },
{ name: 'Acceleration', type: 'measure', defAggFn: 'avg' },
{ name: 'Year', type: 'dimension', subtype: 'datetime', format: '%Y' },
{ name: 'Origin' }
]

getName

Returns the name of the DataModel instance. If no name was specified during DataModel initialization, then it returns a auto-generated name.

Returns:

string: Name of the DataModel instance.

join

Performs crossproduct between two DataModel instances with an optional predicate which determines which tuples should be included and returns a new DataModel instance containing the results. This operation is also called theta join.

Cross product takes two set and create one set where each value of one set is paired with each value of another set.

This method takes an optional predicate which filters the generated result rows. The predicate is called for every tuple. If the predicate returns true the combined row is included in the resulatant table.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 // Creates two small DataModel instance from the original DataModel instance, which will be joined.
 let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
 let nameDM = dm.project(['Name','Miles_per_Gallon']);

 let outputDM = makerDM.join(nameDM,
     (makerDM, nameDM) => makerDM.Maker.value === nameDM.Name.value.split(/\s/)[0]);

Parameters:

NameTypeDescription
joinWith

DataModel

The DataModel to be joined with the current instance DataModel.

filterFn

SelectionPredicate

The predicate function that will filter the result of the crossProduct.

Returns:

DataModelNew DataModel instance created after joining.

naturalJoin

Natural join is a special kind of joining where filtering of rows are performed internally by resolving common fields are from both table and the rows with common value are included.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 // Creates two small DataModel instance from the original DataModel instance, which will be joined.
 let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
 let nameDM = dm.project(['Name','Miles_per_Gallon'])

 let outputDM = makerDM.naturalJoin(nameDM);

Parameters:

NameTypeDescription
joinWith

DataModel

The DataModel with which the current instance of DataModel on which the method is called will be joined.

Returns:

DataModelNew DataModel instance created after joining.

union

Union operation can be termed as vertical stacking of all rows from both the DataModel instances, provided that both of the DataModel instances should have same column names.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 // Creates two small DataModel instance from the original DataModel instance, one only for european cars,
 // another for cars from USA.
 usaMakerDM = dm.select(fields => fields.Origin.value === 'USA');
 euroMakerDM = dm.select(fields => fields.Origin.value === 'Europe');

 outputDM = usaMakerDM.union(euroMakerDM);

Parameters:

NameTypeDescription
unionWith

DataModel

DataModel instance for which union has to be applied with the instance on which the method is called

Returns:

DataModelNew DataModel instance with the result of the operation

difference

Difference operation only include rows which are present in the datamodel on which it was called but not on the one passed as argument.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 // Creates a DataModel instance only including USA
 usaMakerDM = dm.select(fields => fields.Origin.value === 'USA');

 outputDM = dm.difference(usaMakerDM);

Parameters:

NameTypeDescription
differenceWith

DataModel

DataModel instance for which difference has to be applied with the instance on which the method is called

Returns:

DataModelNew DataModel instance with the result of the operation

select

Selection is a row filtering operation. It expects an predicate and an optional mode which control which all rows should be included in the resultant DataModel instance.

SelectionPredicate is a function which returns a boolean value for each tuple present in the DataModel. For selection opearation the predicate function is called for each row of DataModel instance with the current row passed as argument.

After executing SelectionPredicate the rows are labeled as either an member of selection set or an member of rejection set.

FilteringMode operates on the selection and rejection set to determine which one would reflect in the resulatant datamodel.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 let outputDM= dt.select(fields => fields.Origin.value === 'USA')
main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted
 // from muze namespace and assigned to the variable DataModel

const outputDM= dt.select(fields => fields.Origin.value === "USA", { mode: DataModel.FilteringMode.INVERSE })

Parameters:

NameTypeDescription
selectFn

SelectionPredicate

Predicate funciton which is called for each row with the current row

function (row, i) { ... }

config

Object

The configuration object to control the inclusion exclusion of a row in resultant DataModel instance

NameTypeDescription
mode

FilteringMode

The mode of the selection

Returns:

DataModelReturns the new DataModel instance(s) after operation.

project

Projection is column (field) filtering operation. It expects list of fields' name and either include those or exclude those based on FilteringMode on the resultant DataModel instance.

Projection expects array of fields name based on which it creates the selection and rejection set. All the field whose name is present in array goes in selection set and rest of the fields goes in rejection set.

FilteringMode operates on the selection and rejection set to determine which one would reflect in the resulatant datamodel.

main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm.

 let outputDM= dt.project(["Name", "HorsePower"]);
main
run-button
run-button
reset-button
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted
 // from muze namespace and assigned to the variable DataModel

 const outputDM= dt.project(["Name", "HorsePower"], { mode: DataModel.FilteringMode.INVERSE });

Parameters:

NameTypeDescription
projField

Array<(string|Regexp)>

An array of column names in string or regular expression.

config

Object

An optional config to control the creation of new DataModel

NameTypeDescription
mode

FilteringMode

Mode of the projection

logo

Note

Selection and rejection set is only a logical idea for concept explanation purpose.

Projection with default mode FilterningMode.NORMAL

Returns:

DataModelReturns the new DataModel instance after operation.

dispose

Frees up the resources associated with the current DataModel instance and breaks all the links instance has in the DAG.