我正在寻找一个SetJava 实现,它提供基于元素属性的查找。用 Guava 术语思考,它可以使用 a Function<Element, SearchKey>(预计在所有集合元素中都是唯一的)来构造,并提供一个方法find(SearchKey key)返回一个Element函数将为其返回key。
需要满足的明显假设:
function(element)的整个生命周期中都是不变element的。原因:
有时需要Set<Element>并且字段类型不能更改为 a Map<SearchKey, Element>(例如在 JPA 实体中或在第 4 方代码的情况下)。尽管如此,在构建这样一个对象时,人们可以安全地使用他们自己的Set具有类似Map功能的实现。
备择方案:
我已经找到了一些替代方案,但没有一个看起来是完美的
Map类似的功能 - 使用线性搜索find(SearchKey)实现(适用于每个Set实现:)TreeSet与Comparator比较SearchKeys- 有点像hack,特别是这不再尊重元素相等性ceiling并要求您Element为查找目的构建人工(uogh ...)(如果你想回答你不知道更多的选择 - 节省你的时间,不要。这是我已经知道的,我将无法接受你的回答。)
当“通配符嵌套在另一个通配符中”时,我正在努力捕获通配符。可能吗?
代码:
public class ConvolutedGenerics {
// listClass is a class implementing a List of some Serializable type
public void doSomethingWithListOfSerializables(
Class<? extends List<? extends Serializable>> listClass) {
// Capture '? extends Serializable' as 'T extends Serializable'
// The line does not compile with javac 7
captureTheWildcard(listClass); // <------ zonk here
}
// listClass is a class implementing a List of some Serializable type
private <T extends Serializable>
void captureTheWildcard(
Class<? extends List</* ? extends */T>> listClass) {
// Do …Run Code Online (Sandbox Code Playgroud) Presto中的此查询:
select *,
cast(ts_w_tz as timestamp) as ts,
cast(substr(cast(ts_w_tz as varchar), 1, 23) as timestamp) as local_ts_workaround
from (select timestamp '2018-02-06 23:00:00.000 Australia/Melbourne' as ts_w_tz);
Run Code Online (Sandbox Code Playgroud)
返回值:
ts_w_tz | ts | local_ts_workaround
---------------------------------------------+-------------------------+-------------------------
2018-02-06 23:00:00.000 Australia/Melbourne | 2018-02-06 12:00:00.000 | 2018-02-06 23:00:00.000
Run Code Online (Sandbox Code Playgroud)
如您所见,将带有时区的时间戳转换为时间戳的行为导致时间戳被转换回UTC时间(例如ts)。IMO的正确行为应该是根据返回返回时间戳的“墙读” local_ts_workaround。
我意识到有很多关于Presto如何处理此错误和不符合SQL标准的帖子,并且正在修复。但是与此同时,这是一个主要的痛苦,因为其结果是似乎没有构建方法来获得带有OUT时区的本地时间戳(按local_ts_workaround)。
显然,我现在有了字符串转换的解决方法,但这似乎很可怕。我想知道是否有人有更好的解决方法,或者可以指出我错过的内容?
谢谢。
我需要查询类似 AWS Athena 中的内容
SELECT * FROM "hl"."may" where fqk = 'NaN' limit 10
Run Code Online (Sandbox Code Playgroud) 我一直无法获得针对我的 AWS Glue 分区表的任何查询。我得到的错误是
HIVE_METASTORE_ERROR:com.facebook.presto.spi.PrestoException:错误:在“STRING”的位置 0 处应输入类型,但找到“STRING”。(服务:空;状态码:0;错误码:空;请求 ID:空)
我发现另一个线程提出了这样一个事实:数据库名称和表不能包含字母数字和下划线以外的字符。因此,我确保数据库名称、表名称和所有列名称都遵守此限制。唯一不遵守此限制的对象是我的 s3 存储桶名称,该名称很难更改。
以下是数据的表定义和 parquet-tools 转储。
{
"Table": {
"UpdateTime": 1545845064.0,
"PartitionKeys": [
{
"Comment": "call_time year",
"Type": "INT",
"Name": "date_year"
},
{
"Comment": "call_time month",
"Type": "INT",
"Name": "date_month"
},
{
"Comment": "call_time day",
"Type": "INT",
"Name": "date_day"
}
],
"StorageDescriptor": {
"OutputFormat": "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat",
"SortColumns": [],
"InputFormat": "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat",
"SerdeInfo": {
"SerializationLibrary": "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe",
"Name": "ser_de_info_system_admin_created",
"Parameters": {
"serialization.format": "1"
}
},
"BucketColumns": [],
"Parameters": {},
"Location": "s3://ph-data-lake-cududfs2z3xveg5t/curated/system/admin_created/",
"NumberOfBuckets": 0, …Run Code Online (Sandbox Code Playgroud) 我正在运行类似的查询:
SELECT f.*, p.countryName, p.airportName, a.name AS agentName
FROM (
SELECT
f.outboundlegid,
f.inboundlegid,
f.querydatetime,
cast(f.agent as bigint) as agent,
cast(f.querydestinationplace as bigint) as querydestinationplace,
f.queryoutbounddate,
f.queryinbounddate,
f.quoteageinminutes,
f.price
FROM flights f
WHERE querydatetime >= '2018-01-02'
AND querydatetime <= '2019-01-10'
) f
INNER JOIN (
SELECT airportId, airportName, countryName
FROM airports
WHERE countryName IN ('Philippines', 'Indonesia', 'Malaysia', 'Hong Kong', 'Thailand', 'Vietnam')
) p
ON f.querydestinationplace = p.airportId
INNER JOIN agents a
ON f.agent = a.id
ORDER BY f.outboundlegid, f.inboundlegid, f.agent, querydatetime …Run Code Online (Sandbox Code Playgroud) sql query-optimization amazon-web-services presto amazon-athena
我有一个包含 500,000 多条json记录的 S3 存储桶,例如。
{
"userId": "00000000001",
"profile": {
"created": 1539469486,
"userId": "00000000001",
"primaryApplicant": {
"totalSavings": 65000,
"incomes": [
{ "amount": 5000, "incomeType": "SALARY", "frequency": "FORTNIGHTLY" },
{ "amount": 2000, "incomeType": "OTHER", "frequency": "MONTHLY" }
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在 Athena 中创建了一个新表
CREATE EXTERNAL TABLE profiles (
userId string,
profile struct<
created:int,
userId:string,
primaryApplicant:struct<
totalSavings:int,
incomes:array<struct<amount:int,incomeType:string,frequency:string>>,
>
>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ( 'ignore.malformed.json' = 'true')
LOCATION 's3://profile-data'
Run Code Online (Sandbox Code Playgroud)
我对例如感兴趣incomeTypes。"SALARY"、"PENSIONS" …
我想将我的查询输出转换为 python 数据框以绘制折线图
import prestodb
import pandas as pd
conn=prestodb.dbapi.connect(
host='10.0.0.101',
port=8081,
user='hive',
catalog='hive',
schema='ong',
)
cur = conn.cursor()
query="SELECT dtime,tagName FROM machine where tagname is not null
limit 1000"
cur.execute(query)
rows = cur.fetchall()
print(rows)
df = pd.DataFrame(query, columns=['x_axis','tagName'])
Run Code Online (Sandbox Code Playgroud)
这是我的查询输出示例
[['2018-09-08 00:00:00.000', 26], ['2018-09-08 01:00:00.000', 26],
['2018-09-08 02:00:00.000', 26], ['2018-09-08 03:00:00.000', 27],
['2018-09-08 04:00:00.000', 27], ['2018-09-08 05:00:00.000', 27]]
Run Code Online (Sandbox Code Playgroud)
如何使用python将此查询输出转换为数据框
为什么 AWS Athena 在将结果转储到目标 S3 位置时需要“溢出桶”
WITH
( format = 'Parquet',
parquet_compression = 'SNAPPY',
external_location = '**s3://target_bucket_name/my_data**'
)
AS
WITH my_data_2
AS
(SELECT * FROM existing_tablegenerated_data" limit 10)
SELECT *
FROM my_data_2;
Run Code Online (Sandbox Code Playgroud)
既然它已经有了存储数据的桶,为什么 Athena 需要溢出桶以及它在那里存储什么?
我正在尝试使用 presto 将十六进制字符串(以“0x”开头)转换为其整数值。例如0x100256。我的十六进制字符串称为msg_id。我尝试用这个-
from_hex(substr(msg_id,3))
Run Code Online (Sandbox Code Playgroud)
但我遇到了一个问题,因为from_hex期望偶数个十六进制数字(0100而不是100)。我决定尝试使用if语句来解决这个问题,所以我尝试了以下方法:
if(length(msg_id)%2=0, from_hex(substr(msg_id,3)))
Run Code Online (Sandbox Code Playgroud)
(稍后会处理奇数位的情况)
但是 - 的结果from_hex是一种varbinary具有不同字节数的类型。我想将其转换为整数或任何其他数字类型,但我找不到方法。
有任何想法吗?我会很感激...