Skip to content

Commit

Permalink
composite queries for data screen
Browse files Browse the repository at this point in the history
  • Loading branch information
usinesoft committed Nov 13, 2022
1 parent 6241fe2 commit e194402
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.and-query-container{
display: flex;
flex-direction: column;
gap:3px;
padding: 1rem;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.query-line{
display: flex;
flex-direction: row;
gap:3px;
}

.header{
display: flex;
flex-direction: row;
gap:1rem;
}
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
<p>and-query works!</p>
<div class="and-query-container">

<div class="query-line" *ngFor="let q of query.simpleQueries; index as i">
<button mat-mini-fab color="warn" style="margin:0.5rem" aria-label="remove line" matTooltip="remove this line" [disabled]="query.simpleQueries.length == 1"
(click)="removeLine(q)">
<mat-icon>delete</mat-icon>
</button>
<app-simple-query [collection]="collection" [properties]="properties" [query]="q"></app-simple-query>
<div *ngIf="i != query.simpleQueries.length-1">
<p style="margin:1rem">AND</p>
</div>
<div *ngIf="i == query.simpleQueries.length-1">
<button mat-mini-fab color="primary" style="margin:0.5rem" aria-label="add line" matTooltip="add a new line"
(click)="newLine()">
AND
</button>
</div>
</div>

</div>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { AndQuery } from '../model/query';
import { AndQuery, SimpleQuery } from '../model/query';

@Component({
selector: 'app-and-query',
Expand Down Expand Up @@ -28,9 +28,40 @@ export class AndQueryComponent implements OnInit {

@Output() queryChange = new EventEmitter<AndQuery>();


// The name of the collection (mandatory to retrieve query metadata)
private _collection:string|undefined;

public get collection():string | undefined{
return this._collection;
}

@Input()
public set collection(v: string | undefined) {
this._collection = v;
}



// All the queryable properties in the collection
@Input()
public properties: string[] = [];

constructor() { }

ngOnInit(): void {
if(this._query.simpleQueries.length == 0){
this.newLine();
}
}

public newLine(){
this._query.simpleQueries.push(new SimpleQuery)
}

public removeLine(q:SimpleQuery){
var index = this._query.simpleQueries.indexOf(q);
this._query.simpleQueries.splice(index, 1);
}

}
5 changes: 3 additions & 2 deletions CachalotMonitor/ClientApp/src/app/data/data.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
</div>

<div class="query-container" *ngIf="schema">
<app-simple-query [collection]="selectedCollection" [properties]="properties" [(query)]="currentQuery">
</app-simple-query>
<app-and-query [collection]="selectedCollection" [properties]="properties" >
</app-and-query>
</div>


<div>
<p>{{sql}}</p>
</div>
Expand Down
3 changes: 2 additions & 1 deletion CachalotMonitor/ClientApp/src/app/model/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class QueryMetadata {
propertyType: string |undefined;
possibleValues: string[] = [];
availableOperators: string[] = [];
possibleValuesCount:number = 0;
}

export class SimpleQuery{
Expand All @@ -16,5 +17,5 @@ export class SimpleQuery{
}

export class AndQuery{
simpleQueries:SimpleQuery[] = [new SimpleQuery];
simpleQueries:SimpleQuery[] = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
</mat-select>
</mat-form-field>
<!--value(s)-->
<mat-form-field appearance="fill" *ngIf="multipleValuesAllowed" style="flex-grow:2">
<mat-form-field appearance="fill" *ngIf="multipleValuesAllowed && canSelectValues && hasValue" style="flex-grow:2">
<mat-select placeholder="Value(s)" [multiple]="true" [(ngModel)]="selectedValues" #multiSelect>
<!--search box only if more than 10 values-->
<mat-option *ngIf="values.length > 10">
<ngx-mat-select-search [(ngModel)]="searchText" placeholderLabel="Search..."
noEntriesFoundLabel="'no matching value'"></ngx-mat-select-search>
</mat-option>
<mat-option *ngFor="let val of filteredValues " [value]="val">
{{val}}
</mat-option>
</mat-option>
</mat-select>
<mat-hint *ngIf = "multipleValuesAllowed">multiple values allowed (use ,)</mat-hint>
</mat-form-field>
<mat-form-field appearance="fill" *ngIf="!multipleValuesAllowed " style="flex-grow:2">
<mat-form-field appearance="fill" *ngIf="(!multipleValuesAllowed || !canSelectValues) && hasValue " style="flex-grow:2">
<mat-label>Value</mat-label>
<input matInput placeholder="Value" [(ngModel)]="singleValue">
<mat-hint *ngIf = "multipleValuesAllowed">multiple values allowed (use ,)</mat-hint>
</mat-form-field>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export class SimpleQueryComponent implements OnInit {
this.values = [...md.possibleValues];
this.filteredValues = [...md.possibleValues];
this._propertyDataType = md.propertyType;
this._propertyIsCollection = md.propertyIsCollection;
this.working = false;
this._propertyIsCollection = md.propertyIsCollection;
this.operator = md.availableOperators[0];
this.canSelectValues = md.possibleValues.length > 0;
this.working = false;
console.log(`metadata received => data type = ${this._propertyDataType} is collection = ${this._propertyIsCollection}`);
}, _err => {
this.working = true;
Expand All @@ -86,6 +87,11 @@ export class SimpleQueryComponent implements OnInit {


public multipleValuesAllowed:boolean = false;
public canSelectValues:boolean = false;

// "is null" and "is not null" operators can not have values
public hasValue:boolean = true;


public get operator(): string | undefined {
return this.operatorToUnicode(this._query.operator);
Expand All @@ -94,6 +100,13 @@ export class SimpleQueryComponent implements OnInit {
public set operator(v: string | undefined) {
this._query.operator = this.operatorFromUnicode(v);

if(this._query.operator == 'is null' || this._query.operator == 'is not null'){
this.hasValue= false;
}
else{
this.hasValue = true;
}

if((this._query.operator == '=' || this._query.operator == '!=') && this._propertyDataType != 'SomeFloat' && !this._propertyIsCollection){
this.multipleValuesAllowed = true;
}
Expand Down
18 changes: 17 additions & 1 deletion CachalotMonitor/Services/IQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public interface IQueryService
/// </summary>
public class QueryMetadata
{
/// <summary>
/// Max values that are retrieved for client-side search
/// </summary>
public const int MaxValues = 1000;

public string? CollectionName { get; set; }

public string? PropertyName { get; set; }
Expand All @@ -22,7 +27,18 @@ public class QueryMetadata

public bool PropertyIsCollection { get; set; }

public string[] PossibleValues { get; set; } = Array.Empty<string>();

/// <summary>
/// List of possible values if not more than MaxValues
/// </summary>
public string[] PossibleValues { get; set; } = Array.Empty<string>();


/// <summary>
/// Total count of distinct values (useful if more than MaxValues are available)
/// </summary>
public int PossibleValuesCount { get; set; }


public string[] AvailableOperators { get; set; } = Array.Empty<string>();
}
26 changes: 17 additions & 9 deletions CachalotMonitor/Services/QueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public QueryService(IClusterService clusterService)
_clusterService = clusterService;
}




public QueryMetadata GetMetadata(string collection, string property)
{
try
Expand All @@ -33,24 +36,29 @@ public QueryMetadata GetMetadata(string collection, string property)
metadata.CollectionName = collection;
metadata.PropertyName = property;


// query distinct values of the property
var result = _clusterService.Connector?.SqlQueryAsJson($"select distinct {property} from {collection} take 1000").ToList();
var result = _clusterService.Connector?.SqlQueryAsJson($"select distinct {property} from {collection} take {QueryMetadata.MaxValues + 1}").ToList();

if (result == null || result.Count == 0)
{
metadata.AvailableOperators = new[] {"is null", "is not null" };
if (result?.Count == 0) // only if the table is empty
return metadata;
}


if (pr.IsCollection)
{
MetadataForCollectionProperty(property, result, metadata);
MetadataForCollectionProperty(property, result!, metadata);
}
else
{
MetadataForScalarProperty(property, result, metadata);
MetadataForScalarProperty(property, result!, metadata);
}


// if more than max values do not load the network as the result can not be used for query definition
if (result!.Count > QueryMetadata.MaxValues)
{
metadata.PossibleValues = Array.Empty<string>();
}

metadata.PossibleValuesCount = result!.Count;

return metadata;
}
Expand Down
9 changes: 7 additions & 2 deletions Client/Interface/DataAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,19 @@ public IEnumerable<RankedItem> GetMany(OrQuery query, Guid sessionId = default)
var current = clientResult.Current;
if (query.Distinct)
{
if (distinctSet.Add(clientResult.Current)) yield return current;
if (distinctSet.Add(clientResult.Current))
{
count++;
yield return current;
}
}
else
{
count++;
yield return current;
}

count++;

}
}

Expand Down

0 comments on commit e194402

Please sign in to comment.