PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.2.0-rc0/src/java/org/apache/hcatalog/data/HCatRecord.java

#
Java | 136 lines | 80 code | 29 blank | 27 comment | 0 complexity | a12327e3bb26df0ccc77193e64de22a8 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hcatalog.data;
  19. import java.util.List;
  20. import java.util.Map;
  21. import org.apache.hcatalog.common.HCatException;
  22. import org.apache.hcatalog.data.schema.HCatSchema;
  23. /**
  24. * Abstract class exposing get and set semantics for basic record usage.
  25. * Note :
  26. * HCatRecord is designed only to be used as in-memory representation only.
  27. * Don't use it to store data on the physical device.
  28. */
  29. public abstract class HCatRecord implements HCatRecordable {
  30. public abstract Object get(String fieldName, HCatSchema recordSchema) throws HCatException;
  31. public abstract void set(String fieldName, HCatSchema recordSchema, Object value ) throws HCatException;
  32. public abstract void remove(int idx) throws HCatException;
  33. protected Object get(String fieldName, HCatSchema recordSchema, Class clazz) throws HCatException{
  34. // TODO : if needed, verify that recordschema entry for fieldname matches appropriate type.
  35. return get(fieldName,recordSchema);
  36. }
  37. public Boolean getBoolean(String fieldName, HCatSchema recordSchema) throws HCatException {
  38. return (Boolean) get(fieldName, recordSchema, Boolean.class);
  39. }
  40. public void setBoolean(String fieldName, HCatSchema recordSchema, Boolean value) throws HCatException {
  41. set(fieldName,recordSchema,value);
  42. }
  43. public Byte getByte(String fieldName, HCatSchema recordSchema) throws HCatException {
  44. //TINYINT
  45. return (Byte) get(fieldName, recordSchema, Byte.class);
  46. }
  47. public void setByte(String fieldName, HCatSchema recordSchema, Byte value) throws HCatException {
  48. set(fieldName,recordSchema,value);
  49. }
  50. public Short getShort(String fieldName, HCatSchema recordSchema) throws HCatException {
  51. // SMALLINT
  52. return (Short) get(fieldName, recordSchema, Short.class);
  53. }
  54. public void setShort(String fieldName, HCatSchema recordSchema, Short value) throws HCatException {
  55. set(fieldName,recordSchema,value);
  56. }
  57. public Integer getInteger(String fieldName, HCatSchema recordSchema) throws HCatException {
  58. return (Integer) get(fieldName,recordSchema, Integer.class);
  59. }
  60. public void setInteger(String fieldName, HCatSchema recordSchema, Integer value) throws HCatException {
  61. set(fieldName,recordSchema,value);
  62. }
  63. public Long getLong(String fieldName, HCatSchema recordSchema) throws HCatException {
  64. // BIGINT
  65. return (Long) get(fieldName,recordSchema,Long.class);
  66. }
  67. public void setLong(String fieldName, HCatSchema recordSchema, Long value) throws HCatException {
  68. set(fieldName,recordSchema,value);
  69. }
  70. public Float getFloat(String fieldName, HCatSchema recordSchema) throws HCatException {
  71. return (Float) get(fieldName,recordSchema,Float.class);
  72. }
  73. public void setFloat(String fieldName, HCatSchema recordSchema, Float value) throws HCatException {
  74. set(fieldName,recordSchema,value);
  75. }
  76. public Double getDouble(String fieldName, HCatSchema recordSchema) throws HCatException {
  77. return (Double) get(fieldName,recordSchema,Double.class);
  78. }
  79. public void setDouble(String fieldName, HCatSchema recordSchema, Double value) throws HCatException {
  80. set(fieldName,recordSchema,value);
  81. }
  82. public String getString(String fieldName, HCatSchema recordSchema) throws HCatException {
  83. return (String) get(fieldName,recordSchema,String.class);
  84. }
  85. public void setString(String fieldName, HCatSchema recordSchema, String value) throws HCatException {
  86. set(fieldName,recordSchema,value);
  87. }
  88. @SuppressWarnings("unchecked")
  89. public List<? extends Object> getStruct(String fieldName, HCatSchema recordSchema) throws HCatException {
  90. return (List<? extends Object>) get(fieldName,recordSchema,List.class);
  91. }
  92. public void setStruct(String fieldName, HCatSchema recordSchema, List<? extends Object> value) throws HCatException {
  93. set(fieldName,recordSchema,value);
  94. }
  95. public List<?> getList(String fieldName, HCatSchema recordSchema) throws HCatException {
  96. return (List<?>) get(fieldName,recordSchema,List.class);
  97. }
  98. public void setList(String fieldName, HCatSchema recordSchema, List<?> value) throws HCatException {
  99. set(fieldName,recordSchema,value);
  100. }
  101. public Map<?,?> getMap(String fieldName, HCatSchema recordSchema) throws HCatException {
  102. return (Map<?,?>) get(fieldName,recordSchema,Map.class);
  103. }
  104. public void setMap(String fieldName, HCatSchema recordSchema, Map<?,?> value) throws HCatException {
  105. set(fieldName,recordSchema,value);
  106. }
  107. }