table.getn(tableName) 的用法注意。

转自:http://blog.sina.com.cn/s/blog_4a2e9af90100cv1z.html

 

 

1.table.getn(tableName)       

--等同于操作符 #

 

作用:得到一个table的大小。

注意:该table的key必须是有序的,索引是从1开始的。

 

例如:

a)有序table:

local table1 = {10, 20, 30, 50, 1000};

用table.getn(table1) 或 #table1 得到 5。

 

b) 无序table:

local table2 = {

    ["bb"] = 1,

    ["cc"] = 2,

    ["dd"] = 3,

    ["ee"] = nil,

    ["ff"] = 4,

}

用table.getn(table2) 或 #table2  无法得到正确的大小。

 

这种table如果想得到大小一般我这样做:

local count = 0

for k,v in pairs(table2) do

    count = count + 1

end

jdk8 优化以下代码: for (DqExecuteResult dqExecuteResult : dqExecuteResults) { String errorOutputPath = dqExecuteResult.getErrorOutputPath(); Path path = new Path(errorOutputPath); R<List<String>> getFileResult = resourceClient.getFilesAtPath(path.toUri().getPath()); if (null != getFileResult && getFileResult.isSuccess()) { for (String fullPath : getFileResult.getData()) { R<List<String>> previewResult = resourceClient.viewFileByPath(new Path(fullPath).toUri().getPath(), query.getCurrent(), query.getSize(), "\n"); if (null != previewResult && previewResult.isSuccess()) { if("原始库".equals(datasourceName)){ Long datasourceId = iDataSourceClient.queryRawDataSource().getId(); List<MetaColumn> tableColumns = iDataSourceMetaClient.getTableColumns(datasourceId, tableName); for (MetaColumn metaColumn : tableColumns){ headers.add(metaColumn.getColumnName()); } } else if("标准库".equals(datasourceName)){ Long datasourceId = iDataSourceClient.queryModelDataSource().getId(); List<MetaColumn> tableColumns = iDataSourceMetaClient.getTableColumns(datasourceId, tableName); for (MetaColumn metaColumn : tableColumns){ headers.add(metaColumn.getColumnName()); } } int headerSize = headers.size(); List<String> datas = previewResult.getData(); StringBuilder contextBuilder = new StringBuilder(); for(String data : datas){ contextBuilder.append(data.replaceAll("[\r\n\t]", " ")); contextBuilder.append("\n"); } StringReader reader = new StringReader(contextBuilder.toString()); Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(reader); for (CSVRecord record : records) { if (record.size() == headerSize){ List<String> content = new ArrayList<>(); for (String column : record) { content.add(column); } contents.add(content); } } } } } }
06-02
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值