Skip to content

Commit

Permalink
chore: playtomic feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Sep 4, 2024
1 parent 1777c6c commit caf0704
Show file tree
Hide file tree
Showing 22 changed files with 4,041 additions and 3,363 deletions.
50 changes: 40 additions & 10 deletions src/warehouse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ function processWarehouseMessage(message, options) {
message.integrations && message.integrations[options.provider.toUpperCase()]
? message.integrations[options.provider.toUpperCase()].options
: {};

const responses = [];
const eventType = message.type?.toLowerCase();
const skipTracksTable =
Expand All @@ -572,6 +573,25 @@ function processWarehouseMessage(message, options) {
const skipReservedKeywordsEscaping =
options.integrationOptions.skipReservedKeywordsEscaping || false;

// underscoreDivideNumbers when set to false, if a column has a format like "_v_3_", it will be formatted to "_v3_"
// underscoreDivideNumbers when set to true, if a column has a format like "_v_3_", we keep it like that
// For older destinations, it will come as true and for new destinations this config will not be present which means we will treat it as false.
options.underscoreDivideNumbers = options.destConfig?.underscoreDivideNumbers || false;

// allowUsersContextTraits when set to true, if context.traits.* is present, it will be added as context_traits_* and *,
// e.g., for context.traits.name, context_traits_name and name will be added to the user's table.
// allowUsersContextTraits when set to false, if context.traits.* is present, it will be added only as context_traits_*
// e.g., for context.traits.name, only context_traits_name will be added to the user's table.
// For older destinations, it will come as true, and for new destinations this config will not be present, which means we will treat it as false.
const allowUsersContextTraits = options.destConfig?.allowUsersContextTraits || false;

// allowEventContextTraits when set to true, if context.traits.* is present, it will be added as context_traits_* in the events table,
// e.g., for context.traits.name, context_traits_name will be added to the events table.
// allowEventContextTraits when set to false, if context.traits.* is present, nothing will be added in the events table.
// e.g., for context.traits.name, nothing will be added to the events table.
// For older destinations, it will come as true, and for new destinations this config will not be present, which means we will treat it as false.
const allowEventContextTraits = options.destConfig?.allowEventContextTraits || false;

addJsonKeysToOptions(options);

if (isBlank(message.messageId)) {
Expand Down Expand Up @@ -785,6 +805,14 @@ function processWarehouseMessage(message, options) {
...trackProps,
...commonProps,
};
if (!allowEventContextTraits) {
// remove all context traits from eventTableEvent
Object.keys(eventTableEvent).forEach((key) => {
if (key.toLowerCase().startsWith('context_traits_')) {
delete eventTableEvent[key];
}
});
}
const eventTableMetadata = {
table: excludeRudderCreatedTableNames(
utils.safeTableName(
Expand Down Expand Up @@ -827,16 +855,18 @@ function processWarehouseMessage(message, options) {
`${eventType + '_userProperties_'}`,
2,
);
setDataFromInputAndComputeColumnTypes(
utils,
eventType,
commonProps,
message.context ? message.context.traits : {},
commonColumnTypes,
options,
`${eventType + '_context_traits_'}`,
3,
);
if (allowUsersContextTraits) {
setDataFromInputAndComputeColumnTypes(
utils,
eventType,
commonProps,
message.context ? message.context.traits : {},
commonColumnTypes,
options,
`${eventType + '_context_traits_'}`,
3,
);
}
setDataFromInputAndComputeColumnTypes(
utils,
eventType,
Expand Down
10 changes: 1 addition & 9 deletions src/warehouse/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const _ = require('lodash');
const get = require('get-value');

const v0 = require('./v0/util');
const v1 = require('./v1/util');
const { PlatformError, InstrumentationError } = require('@rudderstack/integrations-lib');
const { isBlank } = require('./config/helpers');
Expand Down Expand Up @@ -112,14 +111,7 @@ function validTimestamp(input) {
}

function getVersionedUtils(schemaVersion) {
switch (schemaVersion) {
case 'v0':
return v0;
case 'v1':
return v1;
default:
return v1;
}
return v1;
}

function isRudderSourcesEvent(event) {
Expand Down
87 changes: 0 additions & 87 deletions src/warehouse/v0/util.js

This file was deleted.

9 changes: 6 additions & 3 deletions src/warehouse/v1/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function safeColumnName(options, name = '') {
path to $1,00,000 to path_to_1_00_000
return an empty string if it couldn't find a char if its ascii value doesnt belong to numbers or english alphabets
*/
function transformName(provider, name = '') {
function transformName(options, provider, name = '') {
const extractedValues = [];
let extractedValue = '';
for (let i = 0; i < name.length; i += 1) {
Expand Down Expand Up @@ -120,6 +120,9 @@ function transformName(provider, name = '') {
if (provider === 'postgres') {
key = key.substr(0, 63);
}
if (!options?.underscoreDivideNumbers) {
key = key.replace(/(\w)_(\d+)/g, '$1$2');
}
return key;
}

Expand Down Expand Up @@ -150,15 +153,15 @@ function toBlendoCase(name = '') {

function transformTableName(options, name = '') {
const useBlendoCasing = options.integrationOptions?.useBlendoCasing || false;
return useBlendoCasing ? toBlendoCase(name) : transformName('', name);
return useBlendoCasing ? toBlendoCase(name) : transformName(options, '', name);
}

function transformColumnName(options, name = '') {
const { provider } = options;
const useBlendoCasing = options.integrationOptions?.useBlendoCasing || false;
return useBlendoCasing
? transformNameToBlendoCase(provider, name)
: transformName(provider, name);
: transformName(options, provider, name);
}

module.exports = {
Expand Down
Loading

0 comments on commit caf0704

Please sign in to comment.