<commit_before>import {Input, OnDestroy, OnInit} from "@angular/core";
import * as angular from "angular";
import * as _ from "underscore";

import {FeedDataTransformation} from "../../model/feed-data-transformation";
import {TableSchema} from "../../model/table-schema";
import {UserDatasource} from "../../model/user-datasource";
import {QueryEngine} from "../wrangler/query-engine";

declare const flowchart: any;

const moduleName: string = require("feed-mgr/visual-query/module-name");

/**
 * Code for the delete key.
 */
const DELETE_KEY_CODE = 46;

/**
 * Code for control key.
 */
const CTRL_KEY_CODE = 17;

/**
 * Code for A key.
 */
const A_KEY_CODE = 65;

/**
 * Code for esc key.
 */
const ESC_KEY_CODE = 27;

/**
 * Displays the Build Query step of the Visual Query page.
 *
 * There are two modes for how the user may build their query:
 *
 * - Visual Mode - (default) A {@code QueryEngine} is used to retrieve a list of tables and the schema is displayed in a flow chart. The nodes in the flow chart can be connected to create joins
 * between tables.
 *
 * - Advanced Mode - A textarea is provided for the user to input their query.
 */
export class QueryBuilderComponent implements OnDestroy, OnInit {

    /**
     * Indicates if the UI is in advanced mode
     */
    advancedMode: boolean = false;

    /**
     * Text indicating which node to switch to
     */
    advancedModeText: string;

    /**
     * List of data sources to display.
     */
    availableDatasources: UserDatasource[] = [];

    /**
     * Model for the chart.
     */
    chartViewModel: any;

    /**
     * Indicates that there was an error retrieving the list of tables.
     * @type {boolean} true if there was an error or false otherwise
     */
    databaseConnectionError: boolean = false;

    /**
     * Query engine for determining capabilities.
     */
    @Input()
    engine: QueryEngine<any>;

    /**
     * Error message to be displayed.
     */
    error: string;

    /**
     * Height offset from the top of the page.
     */
    heightOffset: string = "0";

    /**
     * Indicates if the model is valid.
     */
    isValid: boolean = false;

    /**
     * Indicates that the page is being loaded.
     */
    loadingPage: boolean = true;

    /**
     * Indicates that a table schema is being loaded.
     */
    loadingSchema: boolean = false;

    /**
     * Data transformation model
     */
    @Input()
    model: FeedDataTransformation;

    /**
     * Next node id.
     */
    nextNodeID = 10;

    /**
     * List of the data sources used in model.
     * @type {Array.<string>}
     */
    selectedDatasourceIds: string[] = [];

    /**
     * holds the metadata about each column and table that is used to build the SQL str in the getSQLModel() method
     */
    selectedColumnsAndTables: any = [];

    /**
     * Step index (0-based) for this component.
     */
    stepIndex: number;

    /**
     * Step number (1-based) for this component.
     */
    stepNumber: number;

    /**
     * Controller for parent stepper component.
     */
    stepperController: object;

    /**
     * Autocomplete for the table selector.
     */
    tablesAutocomplete: any = {
        clear: this.onAutocompleteClear.bind(this),
        searchText: "",
        selectedTable: null,
        noCache: true,
        querySearch: this.onAutocompleteQuerySearch.bind(this),
        refreshCache: this.onAutocompleteRefreshCache.bind(this),
        delay: 900
    };

    /**
     * List of native data sources to exclude from the model.
     */
    private nativeDataSourceIds: string[] = [];

    /**
     * Constructs a {@code BuildQueryComponent}.
     */
    constructor(private $scope: angular.IScope, $element: angular.IAugmentedJQuery, private $mdToast: angular.material.IToastService, private $mdDialog: angular.material.IDialogService,
                private $document: angular.IDocumentService, private Utils: any, private RestUrlService: any, private HiveService: any, private SideNavService: any, private StateService: any,
                private VisualQueryService: any, private FeedService: any, private DatasourcesService: any) {
        // Setup initializers
        this.$scope.$on("$destroy", this.ngOnDestroy.bind(this));
        this.initKeyBindings();

        // Setup environment<commit_msg>KYLO-1594 Lag in Hive Autocomplete shows table doesnt exist<commit_after>import {Input, OnDestroy, OnInit} from "@angular/core";
import * as angular from "angular";
import * as _ from "underscore";

import {FeedDataTransformation} from "../../model/feed-data-transformation";
import {TableSchema} from "../../model/table-schema";
import {UserDatasource} from "../../model/user-datasource";
import {QueryEngine} from "../wrangler/query-engine";

declare const flowchart: any;

const moduleName: string = require("feed-mgr/visual-query/module-name");

/**
 * Code for the delete key.
 */
const DELETE_KEY_CODE = 46;

/**
 * Code for control key.
 */
const CTRL_KEY_CODE = 17;

/**
 * Code for A key.
 */
const A_KEY_CODE = 65;

/**
 * Code for esc key.
 */
const ESC_KEY_CODE = 27;

/**
 * Displays the Build Query step of the Visual Query page.
 *
 * There are two modes for how the user may build their query:
 *
 * - Visual Mode - (default) A {@code QueryEngine} is used to retrieve a list of tables and the schema is displayed in a flow chart. The nodes in the flow chart can be connected to create joins
 * between tables.
 *
 * - Advanced Mode - A textarea is provided for the user to input their query.
 */
export class QueryBuilderComponent implements OnDestroy, OnInit {

    /**
     * Indicates if the UI is in advanced mode
     */
    advancedMode: boolean = false;

    /**
     * Text indicating which node to switch to
     */
    advancedModeText: string;

    /**
     * List of data sources to display.
     */
    availableDatasources: UserDatasource[] = [];

    /**
     * Model for the chart.
     */
    chartViewModel: any;

    /**
     * Indicates that there was an error retrieving the list of tables.
     * @type {boolean} true if there was an error or false otherwise
     */
    databaseConnectionError: boolean = false;

    /**
     * Query engine for determining capabilities.
     */
    @Input()
    engine: QueryEngine<any>;

    /**
     * Error message to be displayed.
     */
    error: string;

    /**
     * Height offset from the top of the page.
     */
    heightOffset: string = "0";

    /**
     * Indicates if the model is valid.
     */
    isValid: boolean = false;

    /**
     * Indicates that the page is being loaded.
     */
    loadingPage: boolean = true;

    /**
     * Indicates that a table schema is being loaded.
     */
    loadingSchema: boolean = false;

    /**
     * Data transformation model
     */
    @Input()
    model: FeedDataTransformation;

    /**
     * Next node id.
     */
    nextNodeID = 10;

    /**
     * List of the data sources used in model.
     * @type {Array.<string>}
     */
    selectedDatasourceIds: string[] = [];

    /**
     * holds the metadata about each column and table that is used to build the SQL str in the getSQLModel() method
     */
    selectedColumnsAndTables: any = [];

    /**
     * Step index (0-based) for this component.
     */
    stepIndex: number;

    /**
     * Step number (1-based) for this component.
     */
    stepNumber: number;

    /**
     * Controller for parent stepper component.
     */
    stepperController: object;

    /**
     * Autocomplete for the table selector.
     */
    tablesAutocomplete: any = {
        clear: this.onAutocompleteClear.bind(this),
        searchText: "",
        selectedTable: null,
        noCache: true,
        querySearch: this.onAutocompleteQuerySearch.bind(this),
        refreshCache: this.onAutocompleteRefreshCache.bind(this),
        delay: 0
    };

    /**
     * List of native data sources to exclude from the model.
     */
    private nativeDataSourceIds: string[] = [];

    /**
     * Constructs a {@code BuildQueryComponent}.
     */
    constructor(private $scope: angular.IScope, $element: angular.IAugmentedJQuery, private $mdToast: angular.material.IToastService, private $mdDialog: angular.material.IDialogService,
                private $document: angular.IDocumentService, private Utils: any, private RestUrlService: any, private HiveService: any, private SideNavService: any, private StateService: any,
                private VisualQueryService: any, private FeedService: any, private DatasourcesService: any) {
        // Setup initializers
        this.$scope.$on("$destroy", this.ngOnDestroy.bind(this));
        this.initKeyBindings();

        // Setup environment
{'fraction_non_alphanumeric': 0.1105879650895728, 'fraction_numerical': 0.0039044556729444188, 'mean_word_length': 2.494783306581059, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22954', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2394, 'n_words': 829}