Skip to content

Commit

Permalink
cleanup naming for isTemporal
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Dec 5, 2024
1 parent d258c60 commit f6f6833
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/malloy/src/doc/fielddef.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ are an array of ...

## Discriminators

* `isTemporalField` -- `date` or `timestamp` type
* `isTemporalType` -- `date` or `timestamp` type
* `isAtomicFieldType` -- Does type string match the type of one of the atomiv types
* `isRepeatedRecord` -- In some databases this is a type, in other this is an array of record
* `isScalarArray` -- Is a ".each" array
Expand Down
8 changes: 4 additions & 4 deletions packages/malloy/src/lang/ast/expressions/expr-time-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {
ExtractUnit,
isExtractUnit,
isTemporalField,
isTemporalType,
isTimestampUnit,
mkTemporal,
TD,
Expand Down Expand Up @@ -89,13 +89,13 @@ export class ExprTimeExtract extends ExpressionDef {
from: [first, last],
});
}
if (!isTemporalField(first.type)) {
if (!isTemporalType(first.type)) {
return from.first.loggedErrorExpr(
'invalid-type-for-time-extraction',
`Can't extract ${extractTo} from '${first.type}'`
);
}
if (!isTemporalField(last.type)) {
if (!isTemporalType(last.type)) {
return from.last.loggedErrorExpr(
'invalid-type-for-time-extraction',
`Cannot extract ${extractTo} from '${last.type}'`
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ExprTimeExtract extends ExpressionDef {
});
} else {
const argV = from.getExpression(fs);
if (isTemporalField(argV.type)) {
if (isTemporalType(argV.type)) {
return computedExprValue({
dataType: {type: 'number', numberType: 'integer'},
value: {
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/ast/expressions/expr-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Expr,
TemporalFieldType,
TypecastExpr,
isTemporalField,
isTemporalType,
} from '../../../model/malloy_types';

import {FieldSpace} from '../types/field-space';
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ExprTime extends ExpressionDef {
dstType: {type: timeType},
e: expr.value,
};
if (isTemporalField(expr.type)) {
if (isTemporalType(expr.type)) {
toTs.srcType = {type: expr.type};
}
value = toTs;
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/ast/expressions/time-literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {DateTime as LuxonDateTime} from 'luxon';
import {
TemporalFieldType,
TimestampUnit,
isTemporalField,
isTemporalType,
TimeLiteralNode,
} from '../../../model/malloy_types';

Expand Down Expand Up @@ -206,7 +206,7 @@ class GranularLiteral extends TimeLiteral {
}

// Compiler is unsure about rangeEnd = newEnd for some reason
if (rangeEnd && isTemporalField(testValue.type)) {
if (rangeEnd && isTemporalType(testValue.type)) {
const rangeType = testValue.type;
const range = new Range(
new ExprTime(rangeType, rangeStart.value),
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/ast/query-builders/reduce-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
isPartialSegment,
isQuerySegment,
isReduceSegment,
isTemporalField,
isTemporalType,
} from '../../../model/malloy_types';

import {ErrorFactory} from '../error-factory';
Expand Down Expand Up @@ -215,7 +215,7 @@ export class ReduceBuilder extends QuerySegmentBuilder implements QueryBuilder {
fieldAnalytic =
hasExpression(field) && expressionIsAnalytic(field.expressionType);
}
if (isTemporalField(fieldType) || fieldAggregate) {
if (isTemporalType(fieldType) || fieldAggregate) {
reduceSegment.defaultOrderBy = true;
reduceSegment.orderBy = [{field: fieldName, dir: 'desc'}];
usableDefaultOrderField = undefined;
Expand Down
10 changes: 5 additions & 5 deletions packages/malloy/src/lang/ast/types/expression-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Expr,
TimestampUnit,
isDateUnit,
isTemporalField,
isTemporalType,
expressionIsAggregate,
TD,
LeafExpressionType,
Expand Down Expand Up @@ -181,7 +181,7 @@ export class ExprDuration extends ExpressionDef {
): ExprValue {
const lhs = left.getExpression(fs);
this.typeCheck(this, lhs);
if (isTemporalField(lhs.type) && (op === '+' || op === '-')) {
if (isTemporalType(lhs.type) && (op === '+' || op === '-')) {
const num = this.n.getExpression(fs);
if (!TDU.typeEq(num, TDU.numberT)) {
this.logError(
Expand Down Expand Up @@ -253,8 +253,8 @@ function timeCompare(
op: CompareMalloyOperator,
rhs: ExprValue
): Expr | undefined {
const leftIsTime = isTemporalField(lhs.type);
const rightIsTime = isTemporalField(rhs.type);
const leftIsTime = isTemporalType(lhs.type);
const rightIsTime = isTemporalType(rhs.type);
const node = getExprNode(op);
if (leftIsTime && rightIsTime) {
if (lhs.type !== rhs.type) {
Expand Down Expand Up @@ -459,7 +459,7 @@ function delta(
return noGo;
}

const timeLHS = isTemporalField(lhs.type);
const timeLHS = isTemporalType(lhs.type);

const err = errorCascade(timeLHS ? 'error' : 'number', lhs, rhs);
if (err) return err;
Expand Down
7 changes: 4 additions & 3 deletions packages/malloy/src/model/malloy_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export function hasExpression<T extends FieldDef>(
}

export type TemporalFieldType = 'date' | 'timestamp';
export function isTemporalField(s: string): s is TemporalFieldType {
export function isTemporalType(s: string): s is TemporalFieldType {
return s === 'date' || s === 'timestamp';
}
export type CastType =
Expand Down Expand Up @@ -1341,7 +1341,7 @@ export function isLeafAtomic(
): fd is LeafAtomicDef {
return (
fd.type === 'string' ||
isTemporalField(fd.type) ||
isTemporalType(fd.type) ||
fd.type === 'number' ||
fd.type === 'boolean' ||
fd.type === 'json' ||
Expand Down Expand Up @@ -1560,7 +1560,8 @@ export const TD = {
isDate: (td: UTD): td is DateTypeDef => td?.type === 'date',
isTimestamp: (td: UTD): td is TimestampTypeDef => td?.type === 'timestamp',
isTemporal(td: UTD): td is TimestampTypeDef {
return td?.type === 'timestamp' || td?.type === 'date';
const typ = td?.type ?? '';
return isTemporalType(typ);
},
isError: (td: UTD): td is ErrorTypeDef => td?.type === 'error',
eq(x: UTD, y: UTD): boolean {
Expand Down

0 comments on commit f6f6833

Please sign in to comment.