Refactoring Keyword mapping, introducing tuples
This commit is contained in:
@@ -344,7 +344,7 @@ begin
|
||||
var i64 := idx.AsScalar.Value.AsInt64;
|
||||
for var k := 0 to rs.Def.Count - 1 do
|
||||
vals[k] := rs.Fields[rs.Def.Keywords[k]].Items[Integer(i64)].Value;
|
||||
Result := TDataValue.FromScalarRecord(TScalarRecord.Create(rs.Def, vals));
|
||||
Result := TScalarRecord.Create(rs.Def, vals);
|
||||
end
|
||||
else
|
||||
raise EEvaluatorException.Create('Indexer error');
|
||||
@@ -358,10 +358,10 @@ begin
|
||||
if base.IsVoid then
|
||||
exit(TDataValue.Void);
|
||||
case base.Kind of
|
||||
vkRecordSeries: Result := TDataValue.FromSeries(base.AsRecordSeries.Fields[N.Member.Value]);
|
||||
vkScalarRecord: Result := TDataValue(base.AsScalarRecord.Fields[N.Member.Value]);
|
||||
vkRecord: Result := TDataValue(base.AsRecord.Fields[N.Member.Value]);
|
||||
vkStream: Result := TDataValue.FromSeries(base.AsStream.Series.Fields[N.Member.Value]);
|
||||
vkRecordSeries: Result := base.AsRecordSeries.Fields[N.Member.Value];
|
||||
vkScalarRecord: Result := base.AsScalarRecord.Fields[N.Member.Value];
|
||||
vkRecord: Result := base.AsRecord.Fields[N.Member.Value];
|
||||
vkStream: Result := base.AsStream.Series.Fields[N.Member.Value];
|
||||
else
|
||||
raise EEvaluatorException.Create('Member error');
|
||||
end;
|
||||
@@ -377,7 +377,7 @@ begin
|
||||
SetLength(vals, N.Fields.Count);
|
||||
for i := 0 to N.Fields.Count - 1 do
|
||||
vals[i] := Visit(N.Fields[i].Value).AsScalar.Value;
|
||||
Result := TDataValue.FromScalarRecord(TScalarRecord.Create(N.ScalarDefinition, vals));
|
||||
Result := TScalarRecord.Create(N.ScalarDefinition, vals);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@@ -385,16 +385,16 @@ begin
|
||||
SetLength(fields, N.Fields.Count);
|
||||
for i := 0 to N.Fields.Count - 1 do
|
||||
fields[i] := TPair<IKeyword, TDataValue>.Create(N.Fields[i].Key.Value, Visit(N.Fields[i].Value));
|
||||
Result := TDataValue.FromGenericRecord(TGenericRecord<TDataValue>.Create(fields));
|
||||
Result := TGenericRecord<TDataValue>.Create(fields);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEvaluatorVisitor.VisitCreateSeries(const N: ICreateSeriesNode): TDataValue;
|
||||
begin
|
||||
if N.Definition.Trim.StartsWith('[') then
|
||||
Result := TDataValue.FromRecordSeries(TScalarRecordSeries.Create(TRttiAstHelper.JsonToRecordDefinition(N.Definition)))
|
||||
Result := TScalarRecordSeries.Create(TRttiAstHelper.JsonToRecordDefinition(N.Definition))
|
||||
else
|
||||
Result := TDataValue.FromSeries(TScalarSeries.Create(TScalar.StringToKind(N.Definition)));
|
||||
Result := TScalarSeries.Create(TScalar.StringToKind(N.Definition));
|
||||
end;
|
||||
|
||||
function TEvaluatorVisitor.VisitAddSeriesItem(const N: IAddSeriesItemNode): TDataValue;
|
||||
@@ -465,7 +465,7 @@ begin
|
||||
R[k] := rec.Items[k].Value;
|
||||
Result := True;
|
||||
end;
|
||||
Result := TDataValue.FromStream(TPipeStream.Create(config, outputDef, sources, pipeAdapter));
|
||||
Result := TPipeStream.Create(config, outputDef, sources, pipeAdapter);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -540,7 +540,7 @@ begin
|
||||
if Args[1].Kind <> vkMethod then
|
||||
raise EArgumentException.Create('The second argument to Map must be a function.');
|
||||
|
||||
Result := TDataValue.FromSeries(TDataValue.Map(sourceArg.AsSeries, Args[1].AsMethod()));
|
||||
Result := TDataValue.Map(sourceArg.AsSeries, Args[1].AsMethod());
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Reduce(const Args: TArray<TDataValue>): TDataValue;
|
||||
@@ -629,8 +629,7 @@ begin
|
||||
Result := TDataValue(sourceSeries.Items[idx]);
|
||||
end;
|
||||
|
||||
finalSeries := TDataValue.Map(indexSeries, mapperFunc);
|
||||
Result := TDataValue.FromSeries(finalSeries);
|
||||
Result := TDataValue.Map(indexSeries, mapperFunc);
|
||||
end;
|
||||
|
||||
class function TRtlFunctions.Any(const Args: TArray<TDataValue>): TDataValue;
|
||||
|
||||
@@ -482,7 +482,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Result := TDataValue.FromGenericRecord(TGenericRecord<TDataValue>.Create(recFields.ToArray));
|
||||
Result := TGenericRecord<TDataValue>.Create(recFields.ToArray);
|
||||
finally
|
||||
recFields.Free;
|
||||
end;
|
||||
|
||||
+38
-37
@@ -10,6 +10,7 @@ uses
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Series,
|
||||
Myc.Data.Stream,
|
||||
Myc.Data.Tuple,
|
||||
Myc.Data.Keyword;
|
||||
|
||||
type
|
||||
@@ -38,7 +39,6 @@ type
|
||||
|
||||
TDataValue = record
|
||||
type
|
||||
TTuple = TArray<TDataValue>;
|
||||
TFunc = reference to function(const ArgNodes: TArray<TDataValue>): TDataValue;
|
||||
|
||||
private
|
||||
@@ -76,6 +76,13 @@ type
|
||||
class operator Implicit(const AValue: String): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
|
||||
|
||||
class operator Implicit(const AValue: IKeywordMapping<TScalar>): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: IKeywordMapping<TDataValue>): TDataValue; overload; inline;
|
||||
|
||||
class operator Implicit(const AValue: IWriteableScalarRecordSeries): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: ISeries): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: IStream): TDataValue; overload; inline;
|
||||
|
||||
// --- Existing Factories ---
|
||||
class function FromIntf<T: IInterface>(const AValue: T): TDataValue; static;
|
||||
function AsIntf<T: IInterface>: T; inline;
|
||||
@@ -91,12 +98,6 @@ type
|
||||
|
||||
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
|
||||
|
||||
class function FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue; static; inline;
|
||||
class function FromScalarRecord(const AValue: IKeywordMapping<TScalar>): TDataValue; static; inline;
|
||||
class function FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue; static; inline;
|
||||
class function FromSeries(const AValue: ISeries): TDataValue; static; inline;
|
||||
class function FromStream(const AStream: IStream): TDataValue; static; inline;
|
||||
|
||||
// --- Existing Accessors ---
|
||||
function AsScalar: TScalar; inline;
|
||||
function AsMethod: TFunc; inline;
|
||||
@@ -264,36 +265,6 @@ begin
|
||||
FInterface := TObjVal.Create(AValue);
|
||||
end;
|
||||
|
||||
class function TDataValue.FromSeries(const AValue: ISeries): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkSeries;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkRecordSeries;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromScalarRecord(const AValue: IKeywordMapping<TScalar>): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkScalarRecord;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkRecord;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromStream(const AStream: IStream): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkStream;
|
||||
Result.FInterface := AStream;
|
||||
end;
|
||||
|
||||
class function TDataValue.Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries;
|
||||
begin
|
||||
Result := TMapSeries.Create(SourceSeries, MapperFunc);
|
||||
@@ -478,6 +449,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: IKeywordMapping<TScalar>): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkScalarRecord;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: IKeywordMapping<TDataValue>): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkRecord;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: IWriteableScalarRecordSeries): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkRecordSeries;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: ISeries): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkSeries;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: IStream): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkStream;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
{ TMapSeries }
|
||||
|
||||
constructor TMapSeries.Create(const ASourceSeries: ISeries; const AMapperFunc: TDataValue.TFunc);
|
||||
|
||||
Reference in New Issue
Block a user