Skip to content

Commit

Permalink
Merge branch 'main' into andersonf/unify/collect-2
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-joyle authored Mar 6, 2024
2 parents c8a8282 + c333d18 commit 53a5b07
Show file tree
Hide file tree
Showing 70 changed files with 2,465 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/libraries/Microsoft.PowerFx.Core/AssemblyProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@

// NL
[assembly: InternalsVisibleTo("Microsoft.PowerFx.NaturalLanguage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("Microsoft.PowerFx.NLEngine, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
10 changes: 10 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,21 @@ internal static class TexlStrings
public static StringGetter AboutBooleanNT = (b) => StringResources.Get("AboutBooleanNT", b);
public static StringGetter BooleanNTArg1 = (b) => StringResources.Get("BooleanNTArg1", b);

public static StringGetter AboutBooleanW = (b) => StringResources.Get("AboutBooleanW", b);
public static StringGetter BooleanWArg1 = (b) => StringResources.Get("BooleanWArg1", b);
public static StringGetter AboutBooleanWT = (b) => StringResources.Get("AboutBooleanWT", b);
public static StringGetter BooleanWTArg1 = (b) => StringResources.Get("BooleanWTArg1", b);

public static StringGetter AboutBooleanB = (b) => StringResources.Get("AboutBooleanB", b);
public static StringGetter BooleanBArg1 = (b) => StringResources.Get("BooleanBArg1", b);
public static StringGetter AboutBooleanBT = (b) => StringResources.Get("AboutBooleanBT", b);
public static StringGetter BooleanBTArg1 = (b) => StringResources.Get("BooleanBTArg1", b);

public static StringGetter AboutBooleanL = (b) => StringResources.Get("AboutBooleanL", b);
public static StringGetter BooleanLArg1 = (b) => StringResources.Get("BooleanLArg1", b);
public static StringGetter AboutBooleanLT = (b) => StringResources.Get("AboutBooleanLT", b);
public static StringGetter BooleanLTArg1 = (b) => StringResources.Get("BooleanLTArg1", b);

public static StringGetter AboutConcatenate = (b) => StringResources.Get("AboutConcatenate", b);
public static StringGetter ConcatenateArg1 = (b) => StringResources.Get("ConcatenateArg1", b);
public static StringGetter AboutConcatenateT = (b) => StringResources.Get("AboutConcatenateT", b);
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public override LazyList<string> Visit(NumLitNode node, Precedence parentPrecede
Contracts.AssertValue(node);

var nlt = node.Value;
// $$$ can't use current culture

// $$$ can't use current culture
return LazyList<string>.Of(nlt != null ? nlt.ToString() : node.NumValue.ToString("R", CultureInfo.CurrentCulture));
}

Expand All @@ -77,7 +77,7 @@ public override LazyList<string> Visit(DecLitNode node, Precedence parentPrecede
Contracts.AssertValue(node);

var nlt = node.Value;

// $$$ can't use current culture
return LazyList<string>.Of(nlt != null ? nlt.ToString() : node.DecValue.ToString("G29", CultureInfo.CurrentCulture));
}
Expand Down Expand Up @@ -399,8 +399,8 @@ public override LazyList<string> Visit(TableNode node, Precedence parentPreceden
result = LazyList<string>.Of(TexlLexer.PunctuatorBracketOpen, " ")
.With(result)
.With(" ", TexlLexer.PunctuatorBracketClose);

return ApplyPrecedence(parentPrecedence, Precedence.SingleExpr, result);

return result;
}

public virtual string GetRightToken(TexlNode leftNode, Identifier right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class BuiltinFunctionsCore
public static readonly TexlFunction BooleanN = _library.Add(new BooleanNFunction());
public static readonly TexlFunction BooleanN_T = _library.Add(new BooleanNFunction_T());
public static readonly TexlFunction BooleanW = _library.Add(new BooleanWFunction());
public static readonly TexlFunction BooleanW_T = _library.Add(new BooleanWFunction_T());
public static readonly TexlFunction BooleanW_T = _library.Add(new BooleanWFunction_T());
public static readonly TexlFunction Char = _library.Add(new CharFunction());
public static readonly TexlFunction CharT = _library.Add(new CharTFunction());
public static readonly TexlFunction Clock24 = _library.Add(new IsClock24Function());
Expand Down Expand Up @@ -253,9 +253,10 @@ internal class BuiltinFunctionsCore
public static readonly TexlFunction Float = _featureGateFunctions.Add(new FloatFunction());
public static readonly TexlFunction Float_UO = _featureGateFunctions.Add(new FloatFunction_UO());
public static readonly TexlFunction IsUTCToday = _featureGateFunctions.Add(new IsUTCTodayFunction());
public static readonly TexlFunction OptionsSetInfo = _featureGateFunctions.Add(new OptionSetInfoFunction());
public static readonly TexlFunction UTCNow = _featureGateFunctions.Add(new UTCNowFunction());
public static readonly TexlFunction UTCToday = _featureGateFunctions.Add(new UTCTodayFunction());
public static readonly TexlFunction UTCToday = _featureGateFunctions.Add(new UTCTodayFunction());
public static readonly TexlFunction BooleanL = _featureGateFunctions.Add(new BooleanLFunction());
public static readonly TexlFunction BooleanL_T = _featureGateFunctions.Add(new BooleanLFunction_T());

// Slow API, only use for backward compatibility
#pragma warning disable CS0618 // Type or member is obsolete
Expand Down
113 changes: 104 additions & 9 deletions src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/Boolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.PowerFx.Core.Localization;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;
using Microsoft.PowerFx.Functions;
using Microsoft.PowerFx.Syntax;

#pragma warning disable SA1402 // File may only contain a single type
Expand Down Expand Up @@ -158,21 +159,21 @@ internal sealed class BooleanWFunction : BuiltinFunction

// Reusing BooleanN strings as they are generic for numbers
public BooleanWFunction()
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanN, FunctionCategories.Text, DType.Boolean, 0, 1, 1, DType.Decimal)
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanW, FunctionCategories.Text, DType.Boolean, 0, 1, 1, DType.Decimal)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
// Reusing BooleanN strings as they are generic for numbers
yield return new[] { TexlStrings.BooleanNArg1 };
yield return new[] { TexlStrings.BooleanWArg1 };
}

public override bool TryGetParamDescription(string paramName, out string paramDescription)
{
Contracts.AssertNonEmpty(paramName);

return StringResources.TryGet("AboutBooleanN_" + paramName, out paramDescription);
return StringResources.TryGet("AboutBooleanW_" + paramName, out paramDescription);
}
}

Expand All @@ -186,14 +187,14 @@ internal sealed class BooleanWFunction_T : BuiltinFunction

// Reusing BooleanN strings as they are generic for numbers
public BooleanWFunction_T()
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanNT, FunctionCategories.Table, DType.EmptyTable, 0, 1, 1, DType.EmptyTable)
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanWT, FunctionCategories.Table, DType.EmptyTable, 0, 1, 1, DType.EmptyTable)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
// Reusing BooleanN strings as they are generic for numbers
yield return new[] { TexlStrings.BooleanNTArg1 };
yield return new[] { TexlStrings.BooleanWTArg1 };
}

public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary<TexlNode, DType> nodeToCoercedTypeMap)
Expand All @@ -216,7 +217,7 @@ public override bool TryGetParamDescription(string paramName, out string paramDe
Contracts.AssertNonEmpty(paramName);

// Reusing BooleanN strings as they are generic for numbers
return StringResources.TryGet("AboutBooleanNT_" + paramName, out paramDescription);
return StringResources.TryGet("AboutBooleanWT_" + paramName, out paramDescription);
}
}

Expand All @@ -229,13 +230,21 @@ internal sealed class BooleanBFunction : BuiltinFunction
public override bool SupportsParamCoercion => false;

public BooleanBFunction()
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanN, FunctionCategories.Text, DType.Boolean, 0, 1, 1, DType.Boolean)
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanB, FunctionCategories.Text, DType.Boolean, 0, 1, 1, DType.Boolean)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
yield return new[] { TexlStrings.BooleanArg1 };
yield return new[] { TexlStrings.BooleanBArg1 };
}

public override bool TryGetParamDescription(string paramName, out string paramDescription)
{
Contracts.AssertNonEmpty(paramName);

// Reusing BooleanN strings as they are generic for numbers
return StringResources.TryGet("AboutBooleanB_" + paramName, out paramDescription);
}

/// <summary>
Expand Down Expand Up @@ -269,7 +278,7 @@ public BooleanBFunction_T()

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
yield return new[] { TexlStrings.BooleanNTArg1 };
yield return new[] { TexlStrings.BooleanBTArg1 };
}

public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary<TexlNode, DType> nodeToCoercedTypeMap)
Expand Down Expand Up @@ -312,6 +321,92 @@ internal override IR.Nodes.IntermediateNode CreateIRCallNode(PowerFx.Syntax.Call
return base.CreateIRCallNode(node, context, args, scope);
}
}
}

// Boolean(arg:L)
// Corresponding Excel and DAX function: Boolean
internal sealed class BooleanLFunction : BuiltinFunction
{
public override bool IsSelfContained => true;

public override bool SupportsParamCoercion => false;

public BooleanLFunction()
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanL, FunctionCategories.Text, DType.Boolean, 0, 1, 1, DType.OptionSetValue)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
yield return new[] { TexlStrings.BooleanLArg1 };
}

public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary<TexlNode, DType> nodeToCoercedTypeMap)
{
var argType = argTypes[0];

var fValid = base.CheckTypes(context, args, argTypes, errors, out returnType, out nodeToCoercedTypeMap) &&
argType.IsOptionSetBackedByBoolean;

returnType = DType.Boolean;

return fValid;
}

public override bool TryGetParamDescription(string paramName, out string paramDescription)
{
Contracts.AssertNonEmpty(paramName);

return StringResources.TryGet("AboutBooleanL_" + paramName, out paramDescription);
}
}

// Boolean(E:*[L])
// Corresponding Excel and DAX function: Boolean
internal sealed class BooleanLFunction_T : BuiltinFunction
{
public override bool IsSelfContained => true;

public override bool SupportsParamCoercion => false;

public BooleanLFunction_T()
: base(BooleanFunction.BooleanInvariantFunctionName, TexlStrings.AboutBooleanLT, FunctionCategories.Table, DType.EmptyTable, 0, 1, 1, DType.EmptyTable)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
yield return new[] { TexlStrings.BooleanLTArg1 };
}

public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary<TexlNode, DType> nodeToCoercedTypeMap)
{
var fValid = base.CheckTypes(context, args, argTypes, errors, out returnType, out nodeToCoercedTypeMap);
Contracts.Assert(returnType.IsTable);

var arg = args[0];
var argType = argTypes[0];

// Check first that it is a single column table of option set values.
// Next check that the column is not only option sets, but also backed by Booleans.
if (CheckColumnType(context, arg, argType, DType.OptionSetValue, errors, ref nodeToCoercedTypeMap) &&
argType.TypeTree.GetPairs().First().Value.IsOptionSetBackedByBoolean)
{
var rowType = DType.EmptyRecord.Add(new TypedName(DType.Boolean, ColumnName_Value));
returnType = rowType.ToTable();

return true;
}

return false;
}

public override bool TryGetParamDescription(string paramName, out string paramDescription)
{
Contracts.AssertNonEmpty(paramName);

return StringResources.TryGet("AboutBooleanLT_" + paramName, out paramDescription);
}
}

// Boolean(arg:O)
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp
if (!DType.Number.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) &&
!DType.Decimal.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) &&
!DType.String.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) &&
!DType.Boolean.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules))
!DType.Boolean.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) &&
!argType.IsOptionSetBackedByNumber)
{
if (argType.CoercesTo(DType.DateTime, aggregateCoercion: true, isTopLevelCoercion: false, context.Features) && !argType.IsControl)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.PowerFx.Core.Binding.BindInfo;
using Microsoft.PowerFx.Core.Functions;
Expand Down Expand Up @@ -152,9 +153,17 @@ private static bool TryGetParentRecordFieldType(DType aggregateType, TexlNode cu
internal static bool AddAggregateSuggestions(DType aggregateType, IntellisenseData.IntellisenseData intellisenseData, int cursorPos)
{
var suggestionsAdded = false;
var parentRecordNode = intellisenseData.CurNode.Parent as RecordNode;
var alreadyUsedFields = parentRecordNode?.Ids.Select(id => id.Name).ToImmutableHashSet() ?? Enumerable.Empty<DName>().ToImmutableHashSet();
foreach (var tName in aggregateType.GetNames(DPath.Root).Where(param => !param.Type.IsError))
{
var usedName = tName.Name;

if (alreadyUsedFields.Contains(usedName))
{
continue;
}

if (DType.TryGetDisplayNameForColumn(aggregateType, usedName, out var maybeDisplayName))
{
usedName = new DName(maybeDisplayName);
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Types/DType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ internal void AssertValid()

public bool IsOptionSet => Kind == DKind.OptionSet || Kind == DKind.OptionSetValue;

public bool IsOptionSetBackedByNumber => IsOptionSet && OptionSetInfo.BackingKind == DKind.Number;

public bool IsOptionSetBackedByBoolean => IsOptionSet && OptionSetInfo.BackingKind == DKind.Boolean;

public bool IsOptionSetBackedByColor => IsOptionSet && OptionSetInfo.BackingKind == DKind.Color;

public bool IsView => Kind == DKind.View || Kind == DKind.ViewValue;

public bool IsAggregate => IsRecord || IsTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ public static void EnableRegExFunctions(this PowerFxConfig config, TimeSpan regE
config.AdditionalFunctions.Add(func.Key, func.Value);
}
}

[Obsolete("OptionSetInfo function is deprecated. Use the Value function on an option set backed by a number and the Boolean function on an option set backed by a Boolean instead. A new ChoiceInfo function is in the works for access to logical names.")]
public static void EnableOptionSetInfo(this PowerFxConfig powerFxConfig)
{
powerFxConfig.AddFunction(new OptionSetInfoFunction());
}
}
}
Loading

0 comments on commit 53a5b07

Please sign in to comment.