gpt4 book ai didi

azure - 使用 Azure 数据湖分析将 IP 映射到位置

转载 作者:行者123 更新时间:2023-12-02 07:10:51 25 4
gpt4 key购买 nike

我有很多带有 IP(网络博客)的 avro 文件存储在 Azure Blob 中。我想将 IP 映射到位置。如何使用 Azure 数据湖分析 (ADLA) 做到这一点?

现在我有一个 Spark 作业,它使用 Maxmind IP 数据库和一个 java 库,该库读取包含所有 IP 位置数据的 113MB 大 .mmdb 文件来执行此查找。我现在正在调查是否可以将这份工作移交给 ADLA

Maxmind 还提供了一个 C# 库,因此这部分没有问题。然而,对于我来说,如何处理这个需要读取然后用于查找的大 mmdb 文件并不明显。显然,每次 IP 查找读取文件的速度并不快。如何使用 ADLA 处理这种情况(以及类似情况),或者 ADLA 是否不适合此类操作?

如果我有一个正常的程序运行,我会像这样进行查找:

using (var reader = new Reader("GeoIP2-City.mmdb"))
{
foreach(var ip in ips)
{
var data = reader.Find<Dictionary<string, object>>(ip);
...
}
}

maxmind 数据库可在此处获取:https://dev.maxmind.com/geoip/geoip2/downloadable/ (请注意,我已经购买了我当前使用的数据库)以及在此处阅读的 C# 库:https://github.com/maxmind/MaxMind-DB-Reader-dotnet

最佳答案

您可以使用 U-SQL 的 DEPLOY RESOURCE 语句和 UDO 来实现此目的。

首先,必须将文件上传到您的数据湖存储。然后使用 DEPLOY RESOURCE 告诉 U-SQL 系统将该文件复制到脚本运行的每个顶点。然后您的脚本使用 C# 代码来读取该文件。

DEPLOY RESOURCE "/helloworld.txt";

@departments =
SELECT *
FROM (VALUES
(31, "Sales"),
(33, "Engineering"),
(34, "Clerical"),
(35, "Marketing")
) AS D( DepID, DepName );


@departments =
PROCESS @departments
PRODUCE DepID int,
DepName string,
HelloWorld string
USING new Demo.HelloWorldProcessor();

OUTPUT @departments
TO "/departments.tsv"
USING Outputters.Tsv();

这是 U-SQL 处理器 UDO。

using Microsoft.Analytics.Interfaces;
using Microsoft.Analytics.Types.Sql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Demo
{
[SqlUserDefinedProcessor]
public class HelloWorldProcessor : IProcessor
{
private string hw;

public HelloWorldProcessor()
{
this.hw = System.IO.File.ReadAllText("helloworld.txt");
}

public override IRow Process(IRow input, IUpdatableRow output)
{
output.Set<int>("DepID", input.Get<int>("DepID"));
output.Set<string>("DepName", input.Get<string>("DepName"));
output.Set<string>("HelloWorld", hw);
return output.AsReadOnly();
}
}
}

关于azure - 使用 Azure 数据湖分析将 IP 映射到位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45010570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com