Skip to content

Commit

Permalink
feat(query): fix printing of values in resolve value - #1107
Browse files Browse the repository at this point in the history
  • Loading branch information
gigalasr committed Jan 28, 2025
1 parent c205712 commit da5f680
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function executeResolveValueQuery({ dataflow: { graph, environment } }: B
values: [...values]
};
}

return {
'.meta': {
timing: Date.now() - start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type { SlicingCriteria } from '../../../slicing/criterion/parse';
import type { QueryResults, SupportedQuery } from '../../query';
import { bold } from '../../../util/ansi';
import { printAsMs } from '../../../util/time';
import Joi from 'joi';
import Joi, { object } from 'joi';

import { executeResolveValueQuery } from './resolve-value-query-executor';
import { number2ts, RNumberValue, RStringValue } from '../../../r-bridge/lang-4.x/convert-values';


export interface ResolveValueQuery extends BaseQueryFormat {
Expand All @@ -19,6 +20,25 @@ export interface ResolveValueQueryResult extends BaseQueryResult {
results: Record<string, {values: unknown[]}>
}

function rValueToAscii(value: string | RNumberValue | RStringValue): string {
if(value === null || value === undefined) {
return 'undefined';
} else if(typeof value === 'string') {
return value;
} else if(typeof value === 'object') {
if("num" in value) {
return value.num.toString();
} else if ("str" in value) {
return `${value.quotes}${value.str}${value.quotes}`;
} else {
console.warn("omega lul")
return JSON.stringify(value);
}
}

return value;
}

export const ResolveValueQueryDefinition = {
executor: executeResolveValueQuery,
asciiSummarizer: (formatter, _processed, queryResults, result) => {
Expand All @@ -27,7 +47,7 @@ export const ResolveValueQueryDefinition = {
for(const [fingerprint, obj] of Object.entries(out.results)) {
const { criteria } = JSON.parse(fingerprint) as ResolveValueQuery;
result.push(` ╰ Values for {${criteria.join(', ')}}`);
result.push(` ╰ ${obj.values.join(', ')}`);
result.push(` ╰ ${obj.values.map(v => rValueToAscii(v as string | RNumberValue | RStringValue)).join(', ')}`);
}
return true;
},
Expand Down

0 comments on commit da5f680

Please sign in to comment.