Skip to content

Commit

Permalink
#2294 changed validation rule for timestamp column
Browse files Browse the repository at this point in the history
Validation target must not include null or empty value.
  • Loading branch information
minhyun2 authored and ufoscw committed Jul 17, 2019
1 parent f7b1104 commit 4eeb249
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {FieldConfigService} from "../../service/field-config.service";
import {StringUtil} from "../../../common/util/string.util";
import {DatasourceService} from "../../../datasource/service/datasource.service";
import {TimeZoneObject, TimezoneService} from "../../service/timezone.service";
import {GranularityService} from "../../service/granularity.service";

declare const moment;

Expand Down Expand Up @@ -125,6 +126,7 @@ export class SchemaConfigureFieldDetailComponent extends AbstractComponent imple
private fieldConfigService: FieldConfigService,
private datasourceService: DatasourceService,
private timezoneService: TimezoneService,
private granularityService: GranularityService,
protected element: ElementRef,
protected injector: Injector) {
super(element, injector);
Expand Down Expand Up @@ -262,7 +264,7 @@ export class SchemaConfigureFieldDetailComponent extends AbstractComponent imple
public getDefaultIngestionRuleValue(): string | number {
switch (this.selectedField.logicalType) {
case LogicalType.TIMESTAMP:
return (this.selectedField.format && this.selectedField.format.type === FieldFormatType.DATE_TIME) ? this.dataList[0] : this._currentMilliseconds;
return (this.selectedField.format && this.selectedField.format.type === FieldFormatType.DATE_TIME) ? this.granularityService.getAvailableStartData(this.dataList, 0) : this._currentMilliseconds;
case LogicalType.BOOLEAN:
return 'false';
case LogicalType.TEXT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import {Injectable, Injector} from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import {TranslateService} from '@ngx-translate/core';
import {FieldFormatType, FieldFormatUnit} from "../../domain/datasource/datasource";

declare let moment: any;
Expand Down Expand Up @@ -103,7 +103,7 @@ export class GranularityService {
* @return {GranularityIntervalInfo}
*/
public getInitializedInterval(fieldDataList: any[], format: string, granularity: GranularityObject, type: FieldFormatType, unit: FieldFormatUnit): GranularityIntervalInfo {
const firstMoment = this._getConvertedMoment(fieldDataList[0], format, type, unit);
const firstMoment = this._getConvertedMoment(this.getAvailableStartData(fieldDataList, 0), format, type, unit);
const endMoment = this._getConvertedMoment(this._getAvailableEndData(fieldDataList, fieldDataList.length-1), format, type, unit);
// init
const result: GranularityIntervalInfo = {
Expand Down Expand Up @@ -161,6 +161,16 @@ export class GranularityService {
return result;
}

/**
* Get available Start Data
* @param {any[]} dataList
* @param {number} startNumber
* @return {any}
*/
public getAvailableStartData(dataList: any[], startNumber: number): any {
return dataList[startNumber] || (startNumber === dataList.length -1 ? moment() : this.getAvailableStartData(dataList, startNumber + 1));
}

/**
* Is valid interval
* @param {string} dateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ public boolean checkTimeFormat(TimeFormatCheckRequest request) {

public boolean checkUnixTimeFormat(List<String> samples) {

int totalCount = samples.size();
int count = 0;
for (String timeStr : samples) {
if(StringUtils.isNumeric(timeStr)) {
if (StringUtils.isBlank(timeStr)) {
totalCount--;
} else if(StringUtils.isNumeric(timeStr)) {
count++;
}
}

if (count >= samples.size() * 0.5) {
if (count >= totalCount * 0.5) {
return true;
}

Expand All @@ -124,18 +127,23 @@ public boolean checkUnixTimeFormat(List<String> samples) {

public boolean checkTimeFormat(DateTimeFormatter formatter, List<String> samples) {

int totalCount = samples.size();
int count = 0;
for (String timeStr : samples) {
try {
formatter.withLocale(Locale.ENGLISH).parseDateTime(timeStr);
} catch (Exception e) {
LOGGER.warn("Invalid date format - no match : " + e.getMessage());
continue;
if (StringUtils.isBlank(timeStr)) {
totalCount--;
} else {
try {
formatter.withLocale(Locale.ENGLISH).parseDateTime(timeStr);
} catch (Exception e) {
LOGGER.warn("Invalid date format - no match : " + e.getMessage());
continue;
}
count++;
}
count++;
}

if (count >= samples.size() * 0.5) {
if (count >= totalCount * 0.5) {
return true;
}

Expand Down

0 comments on commit 4eeb249

Please sign in to comment.