1. 程式人生 > >Hbase插入資料的模組化操作案例

Hbase插入資料的模組化操作案例

	private void insertHbaseDBForSports(String dataType, String appType, String collectDate,
			List<Map<String, String>> dataValue, String phone, String deviceID) throws Exception {
		HQuery hquery = new HQuery();
		String stringDate = DateUtil.dateToString(collectDate);
		long time = DateUtil.getTime(stringDate);
		long Datetime = Long.MAX_VALUE - time;
		String rowkey = phone + "_" + Datetime + "_" + appType + "_" + dataType + DateUtil.getCurrentTime();
		hquery.setRow(rowkey);
		hquery.setTable(sportTable);
		List<HBaseColumn> columns = hquery.getColumns();
		columns.add(new HBaseColumn(sportFamily, qualifierPhone, phone));
		columns.add(new HBaseColumn(sportFamily, qualifierDeviceId, deviceID));
		columns.add(new HBaseColumn(sportFamily, qualifierCompany, "bigData"));
		columns.add(new HBaseColumn(sportFamily, qualifierAppType, appType));
		columns.add(new HBaseColumn(sportFamily, qualifierDataType, dataType));
		columns.add(new HBaseColumn(sportFamily, qualifierDataValue,
				JSONArray.fromObject(dataValue).toString()));
		columns.add(new HBaseColumn(sportFamily, qualifierReceiveDateTime, collectDate.toString()));
		columns.add(new HBaseColumn(sportFamily, "id", rowkey));
		sportsDataHbaseDao.addSportsData(hquery);
	}