microsoft / microsoft/Power-Fx

FileInfo functions

Open
#2,343 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

Add 2 new functions that work with files (https://github.com/microsoft/Power-Fx/blob/main/src/libraries/Microsoft.PowerFx.Core/Public/Values/BlobValue.cs)

These don't need to be included by default yet. But can be pulled in via:
Config.EnableFileFunctions()

FileInfo

New function, called "FileInfo", which takes a blob and returns a record of file information:

FileInfo(Blob): FileInfo

Where:

FileInfo = Type(
{
    Name: Text,
    Size: Decimal, // 53 bits is large enough 
    MIMEType: Text,
    URL: Text
});

Blob is a File type in Power Fx (Dtype.Blob)
Note: Power Fx only has Floating point /Decimal numberic types (no integer types).

Text(Blob) // should return appres URL, not impl in C# interpreter yet.

// semantically same as:
FileInfo(Blob).URL

PatchFileInfo

PatchFileInfo( File: Blob, UpdatedInfo: FileInfo ): Blob

For changing the file name, it would be PatchFileInfo( MyFile, { Name: "My new file name" } ).

Won't allow updating Size/Url. Runtime error.
So this would be an error:
PatchFileInfo(Blob, FileInfo(blob))

Open Issues:

  1. Size is Number of Decimal?
  2. Final name of PatchFileInfo

Implementation plan

  1. In C# side, we define new virtuals on BlobValue for GetFileInfo, SetFileInfo.
  2. Power Fx side defines the two functions above
  3. Their impl will call the new virtuals on BlobValue

Hosts are already derive from BlobValue, and so you would just implement those virtuals as you see fit.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/libraries/Microsoft.PowerFx.Core/Public/Values/BlobValue.cs and review the proposed GetFileInfo and SetFileInfo virtuals. Trace how Config.EnableFileFunctions() exposes functions and how BlobValue hosts are implemented. Done means FileInfo and PatchFileInfo are defined with the specified Blob and record behavior, including runtime errors for unsupported Size and URL updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.