Răsfoiți Sursa

[analyser] Add tests to SqlAnalyzer abd checkMissingLimit()

Romain Rigaux 4 ani în urmă
părinte
comite
44155e8cc3

+ 58 - 0
desktop/core/src/desktop/js/catalog/optimizer/SqlAnalyser.test.ts

@@ -0,0 +1,58 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import Connector from '../types/config';
+import SqlAnalyzer from './SqlAnalyzer';
+
+const connectorA: Connector = {
+  buttonName: '',
+  displayName: '',
+  id: 'connectorA',
+  page: '',
+  tooltip: '',
+  type: ''
+};
+
+describe('SqlAnalyzer.ts', () => {
+  describe('checkMissingLimit', () => {
+    it('Should detect a missing LIMIT', async () => {
+      const isMissingLimit = await new SqlAnalyzer(connectorA).checkMissingLimit(
+        'SELECT * FROM employee',
+        'hive'
+      );
+
+      expect(isMissingLimit).toBeTruthy();
+    });
+
+    it('Should avoid warning from a missing LIMIT in SELECT without a table', async () => {
+      const isMissingLimit = await new SqlAnalyzer(connectorA).checkMissingLimit(
+        'SELECT 1',
+        'hive'
+      );
+
+      expect(isMissingLimit).toBeFalsy();
+    });
+
+    it('Should not warning from a missing LIMIT in CREATE', async () => {
+      const isMissingLimit = await new SqlAnalyzer(connectorA).checkMissingLimit(
+        'CREATE TABLE a (a int)',
+        'hive'
+      );
+
+      expect(isMissingLimit).toBeFalsy();
+    });
+  });
+});

+ 1 - 0
desktop/core/src/desktop/js/ko/components/assist/ko.assistEditorContextPanel.js

@@ -693,6 +693,7 @@ class AssistEditorContextPanel {
 
           return false;
         }
+
         return true;
       });
     }