Skip to content

Commit

Permalink
SNOW-920977: Add space formatting rules to eslint configuration (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Sep 22, 2023
1 parent fc83f25 commit fe8144c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ module.exports = {
'ecmaVersion': 'latest'
},
'rules': {
'array-bracket-spacing': ['warn'],
'arrow-spacing': ['warn'],
'block-spacing': ['warn'],
'brace-style': ['warn', '1tbs'],
'comma-spacing': ['warn'],
'curly': ['warn', 'all'],
'indent': ['warn', 2],
'key-spacing': ['warn'],
'keyword-spacing': ['warn'],
'linebreak-style': ['warn', 'unix'],
'no-async-promise-executor': ['warn'],
'no-console': ['warn', { 'allow': ['warn', 'error'] }],
Expand All @@ -31,8 +37,16 @@ module.exports = {
'no-useless-catch': ['warn'],
'no-useless-escape': ['warn'],
'no-var': ['warn'],
'object-curly-spacing': ['warn', 'always'],
'prefer-const': ['warn'],
'quotes': ['warn', 'single'],
'semi': ['warn', 'always']
'semi': ['warn', 'always'],
'semi-spacing': ['warn'],
'space-before-function-paren': ['warn', {
'anonymous': 'always',
'named': 'never',
'asyncArrow': 'always',
}],
'space-infix-ops': ['warn'],
}
};
34 changes: 17 additions & 17 deletions lib/queryContextCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Logger = require('./logger');
* @param {Number} priority
* @param {String} context
*/
function QueryContextElement (id,timestamp,priority,context) {
function QueryContextElement(id, timestamp, priority, context) {
this.id = id;
this.timestamp = timestamp;
this.priority = priority;
Expand All @@ -25,20 +25,20 @@ function QueryContextElement (id,timestamp,priority,context) {
/**
* @param {Number} capacity Maximum capacity of the cache.
*/
function QueryContextCache (capacity) {
function QueryContextCache(capacity) {
this.capacity = capacity;
this.idMap = new Map(); // Map for id and QCC
this.treeSet = new Set(); // Order data as per priority
this.priorityMap = new Map(); // Map for priority and QCC
}

QueryContextCache.prototype.sortTreeSet = function () {
this.treeSet = new Set(Array.from(this.treeSet).sort((a,b)=>a.priority-b.priority));
this.treeSet = new Set(Array.from(this.treeSet).sort((a, b) => a.priority - b.priority));
};

QueryContextCache.prototype.addQCE= function (qce) {
this.idMap.set(qce.id,qce);
this.priorityMap.set(qce.priority,qce);
QueryContextCache.prototype.addQCE = function (qce) {
this.idMap.set(qce.id, qce);
this.priorityMap.set(qce.priority, qce);
this.treeSet.add(qce);
this.sortTreeSet();
};
Expand Down Expand Up @@ -114,7 +114,7 @@ QueryContextCache.prototype.merge = function (newQCE) {

// new priority
// Add new element in the cache
this.addQCE(newQCE,newQCE);
this.addQCE(newQCE, newQCE);
}
}
};
Expand Down Expand Up @@ -156,7 +156,7 @@ QueryContextCache.prototype.getElements = function () {
QueryContextCache.prototype.deserializeQueryContext = function (data) {
const stringifyData = JSON.stringify(data);
Logger.getInstance().debug(`deserializeQueryContext() called: data from server: ${stringifyData}`);
if (!data || stringifyData ==='{}' || data.entries === null) {
if (!data || stringifyData === '{}' || data.entries === null) {

this.clearCache();
Logger.getInstance().debug('deserializeQueryContext() returns');
Expand Down Expand Up @@ -214,10 +214,10 @@ QueryContextCache.prototype.deserializeQueryContext = function (data) {
};

QueryContextCache.prototype.deserializeQueryContextElement = function (node) {
const {id, timestamp, priority, context} = node;
const { id, timestamp, priority, context } = node;
const entry = new QueryContextElement (id, timestamp, priority, null);

if(typeof context === 'string'){
if (typeof context === 'string'){
entry.context = context;
} else if (context === null || context === undefined) {
entry.context = null;
Expand All @@ -232,23 +232,23 @@ QueryContextCache.prototype.deserializeQueryContextElement = function (node) {

QueryContextCache.prototype.logCacheEntries = function () {

this.treeSet.forEach(function(elem) {
this.treeSet.forEach(function (elem) {
Logger.getInstance().debug(
`Cache Entry: id: ${elem.id} timestamp: ${elem.timestamp} priority: ${elem.priority}`,
);
});
};

QueryContextCache.prototype.getSize = function() {
QueryContextCache.prototype.getSize = function () {
return this.treeSet.size;
};

QueryContextCache.prototype.getQueryContextDTO = function () {
const arr = [];
const querycontexts =Array.from(this.getElements());
const querycontexts = Array.from(this.getElements());
for (let i = 0; i < this.treeSet.size; i++) {
arr.push({id:querycontexts[i].id, timestamp:querycontexts[i].timestamp,
priority:querycontexts[i].priority, context:{base64Data:querycontexts[i].context}||null});
arr.push({ id: querycontexts[i].id, timestamp: querycontexts[i].timestamp,
priority: querycontexts[i].priority, context: { base64Data: querycontexts[i].context } || null });
}
return {
entries: arr
Expand All @@ -257,9 +257,9 @@ QueryContextCache.prototype.getQueryContextDTO = function () {

QueryContextCache.prototype.getSerializeQueryContext = function () {
const arr = [];
const querycontexts =Array.from(this.getElements());
const querycontexts = Array.from(this.getElements());
for (let i = 0; i < this.treeSet.size; i++) {
arr.push({id:querycontexts[i].id,timestamp:querycontexts[i].timestamp,priority:querycontexts[i].priority,context:querycontexts[i].context||null});
arr.push({ id: querycontexts[i].id, timestamp: querycontexts[i].timestamp, priority: querycontexts[i].priority, context: querycontexts[i].context || null });
}

return {
Expand Down
36 changes: 18 additions & 18 deletions test/integration/testHTAP.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,61 @@ if (process.env.CLOUD_PROVIDER === 'AWS') {

const querySet = [
{
sqlTexts:[
sqlTexts: [
'create or replace database db1',
'create or replace hybrid table t1 (a int primary key, b int)',
'insert into t1 values (1, 2), (2, 3), (3, 4)'
],
QccSize:2,
QccSize: 2,
},
{
sqlTexts:[
sqlTexts: [
'create or replace database db2',
'create or replace hybrid table t2 (a int primary key, b int)',
'insert into t2 values (1, 2), (2, 3), (3, 4)'
],
QccSize:3,
QccSize: 3,
},
{
sqlTexts:[
sqlTexts: [
'create or replace database db3',
'create or replace hybrid table t3 (a int primary key, b int)',
'insert into t3 values (1, 2), (2, 3), (3, 4)'
],
QccSize:4,
QccSize: 4,
},
{
sqlTexts:[
sqlTexts: [
'select * from db1.public.t1 x, db2.public.t2 y, db3.public.t3 z where x.a = y.a and y.a = z.a;',
'select * from db1.public.t1 x, db2.public.t2 y where x.a = y.a;',
'select * from db2.public.t2 y, db3.public.t3 z where y.a = z.a;'
],
QccSize:4,
QccSize: 4,
},
];

function createQueryTest () {
function createQueryTest() {
const testingSet = [];
let testingfunction;
for(let i = 0; i < querySet.length; i++) {
const {sqlTexts,QccSize} = querySet[i];
for(let k = 0; k < sqlTexts.length; k++){
if(k!==sqlTexts.length-1){
testingfunction = function(callback) {
for (let i = 0; i < querySet.length; i++) {
const { sqlTexts, QccSize } = querySet[i];
for (let k = 0; k < sqlTexts.length; k++){
if (k !== sqlTexts.length - 1){
testingfunction = function (callback) {
connection.execute({
sqlText: sqlTexts[k],
complete: function (err) {
assert.ok(!err,'There should be no error!');
assert.ok(!err, 'There should be no error!');
callback();
}
});
};
} else{
testingfunction = function(callback) {
} else {
testingfunction = function (callback) {
connection.execute({
sqlText: sqlTexts[k],
complete: function (err, stmt) {
assert.ok(!err,'There should be no error!');
assert.ok(!err, 'There should be no error!');
assert.strictEqual(stmt.getQueryContextCacheSize(), QccSize);
assert.strictEqual(stmt.getQueryContextDTOSize(), QccSize);
callback();
Expand Down

0 comments on commit fe8144c

Please sign in to comment.