Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

KustoCode.ParseAndAnalyze does not parse RealLiteralExpressions in non-english cultures

未关闭
#197 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp
领域
compilers

调研方向

从 KustoCode.ParseAndAnalyze 开始,跟踪 RealLiteralExpression 的构造及其 LiteralValue 转换。在希腊语和法语区域性下,使用 print 123.456 和 datatable(A:real)[123.456,789] 重现该问题,然后验证数值字面量在不更改其 LiteralText 的情况下保留不变区域性的值。

由索引模型根据 Issue 内容生成。

描述

The input
print 123.456
will generate a parse-tree with a LiteralExpression whose LiteralValue property contains 123456 if the culture is set to Greek. If the culture is set to french, it will generate a LiteralValue of 0

This seems incorrect; the documentation I've found implies that KQL always uses invariant-culture for number parsing. Note, this is not problem with the print operator; the same issue can be demonstrated with

datatable(A:real)[123.456,789]

The following code can be used to demonstrate the problem

using System.Globalization;
using System.Text;
using Kusto.Language;
using Kusto.Language.Symbols;
using Kusto.Language.Syntax;

var cultureName = "el-GR"; //problem found with greek culture but also demonstrated with french
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture = new CultureInfo(cultureName);

var query = "print 123.456";

var kustoCode = KustoCode.ParseAndAnalyze(query, GlobalState.Default);
DumpKustoTree(kustoCode);
return;

void DumpKustoTree(KustoCode tree)
{
    var sb = new StringBuilder();
    var indent = 0;
    SyntaxElement.WalkNodes(
        tree.Syntax,
        node =>
        {
            sb.Append(new string(' ', indent));
            sb.AppendLine(
                $"{node.Kind}: {node.ToString(IncludeTrivia.SingleLine)}: {SchemaDisplay.GetText((node as Expression)?.ResultType)}");
            if (node is LiteralExpression literal)
            {
                var value = literal.LiteralValue;
                var v = value is IFormattable f
                    ? f.ToString(null, CultureInfo.InvariantCulture)
                    : value?.ToString() ?? "<null>";
                sb.AppendLine(new string(' ', indent) + $"LITERAL {value!.GetType().Name}  {v}");
            }

            indent++;
        },
        _ => { indent--; });

    Console.WriteLine(sb.ToString());
}

This generates the following output:

QueryBlock: print 123.456:
 List: :
 List: print 123.456:
  SeparatedElement: print 123.456:
   ExpressionStatement: print 123.456:
    PrintOperator: print 123.456: (print_0: real)
     List: 123.456:
      SeparatedElement: 123.456:
       RealLiteralExpression: 123.456: real
       LITERAL Double  123456

The problem occurs as far back as version 11.0.0 of the library.

It's possible that there is some hidden setup or parameter I'm missing that would force the use of invariant culture, other than that the best workarounds would seem to be to force the current culture to Invariant while parsing or perhaps to ignore the LiteralValue in the property and parse it out manually from the LiteralText using invariantculture.

主要语言
C#
星标
684
派生
122
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/Kusto-Query-Language 的其他 Issue

查看 microsoft/Kusto-Query-Language 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。