我正在尝试从Linux(Red Hat 7.3 64位)上的.netcore(v.1.0.1)应用程序连接到Hive。
Program.cs代码:
nextTick
我的项目设置文件: app.csproj
using System;
using System.Data.Odbc;
using System.Collections;
using System.Collections.Generic;
namespace app
{
class Program
{
static void Main(string[] args)
{
var connectionString = "DSN=Hadoop Hive";
var createTableCommandText = "CREATE TABLE Searches(searchTerm STRING, userid BIGINT,userIp STRING) " +
"COMMENT 'Stores all searches for data' " +
"PARTITIONED BY(searchTime DATE) " +
"STORED AS SEQUENCEFILE;";
using (var connection = new OdbcConnection(connectionString))
{
using (var command = new OdbcCommand(createTableCommandText, connection))
{
try
{
connection.Open();
// Create a table.
command.ExecuteNonQuery();
// Insert row of data.
command.CommandText = "INSERT INTO TABLE Searches PARTITION (searchTime = '2015-02-08') " +
"VALUES ('search term', 1, '127.0.0.1')";
command.ExecuteNonQuery();
// Reading data from Hadoop.
command.CommandText = "SELECT * FROM Searches";
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
for (var i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(reader[i]);
}
}
}
}
catch (OdbcException ex)
{
Console.WriteLine(ex.Message);
throw;
}
finally
{
Drop table
command.CommandText = "DROP TABLE Searches";
command.ExecuteNonQuery();
}
}
}
运行“dotnet run”时收到以下错误:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageId>HadoopLibrary</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.0.1" />
<PackageReference Include="MSA.NetCore.ODBC" Version="1.0.3" />
</ItemGroup>
任何人都可以帮忙解决这个问题吗?驱动程序(Hortonworks ODBC for Hive)在此服务器上运行。这里的ODBC连接库存在问题。
答案 0 :(得分:0)
您似乎正在尝试将其构建和加载为32位应用程序,而Hortonworks ODBC for Hive可能不支持该功能。为此,需要检查Hortonworks的文档。