Exemplo n.º 1
0
func (p *DataPage) createDecoder(rb *bufio.Reader, page *DictionaryPage) (encoding.Decoder, error) {

	numValues := uint(p.header.NumValues)

	switch p.header.Encoding {
	case thrift.Encoding_BIT_PACKED:
	case thrift.Encoding_DELTA_BINARY_PACKED:
	case thrift.Encoding_DELTA_BYTE_ARRAY:
	case thrift.Encoding_DELTA_LENGTH_BYTE_ARRAY:
	case thrift.Encoding_PLAIN:
		return encoding.NewPlainDecoder(rb, numValues), nil
	case thrift.Encoding_RLE:

	case thrift.Encoding_RLE_DICTIONARY:
		fallthrough
	case thrift.Encoding_PLAIN_DICTIONARY:
		if page == nil {
			return nil, fmt.Errorf("data page in dictionary page format but no dictionary was defined")
		}
		return encoding.NewPlainDictionaryDecoder(rb, page, numValues), nil
	default:
		panic("Not supported type for " + p.header.GetEncoding().String())
	}

	panic("NYI")
}
Exemplo n.º 2
0
//Decode Read a dictionary page. There is only one dictionary page for each column chunk
func (p *DictionaryPage) Decode(r io.Reader) error {

	// r = dump(r)

	count := p.count
	_type := p.t

	//log.Println("dictionaryPage.Decode:", p.header.GetEncoding(), p.t, count)

	switch p.header.GetEncoding() {

	case thrift.Encoding_PLAIN_DICTIONARY:
		decoder := encoding.NewPlainDecoder(r, count)
		switch _type {
		case thrift.Type_BOOLEAN:
			read, err := decoder.DecodeBool(p.valuesBool)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_INT32:
			read, err := decoder.DecodeInt32(p.valuesInt32)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_INT64:
			read, err := decoder.DecodeInt64(p.valuesInt64)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_INT96:
			read, err := decoder.DecodeInt96(p.valuesInt96)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_BYTE_ARRAY:
			read, err := decoder.DecodeByteArray(p.valuesByteArray)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_FIXED_LEN_BYTE_ARRAY:
			read, err := decoder.DecodeFixedByteArray(p.valuesByteArray, p.typeLength)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}

		case thrift.Type_DOUBLE:
			read, err := decoder.DecodeFloat64(p.valuesFloat64)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		case thrift.Type_FLOAT:
			read, err := decoder.DecodeFloat32(p.valuesFloat32)
			if err != nil || read != count {
				return fmt.Errorf("could not read all dataPage encoded values")
			}
		default:
			return fmt.Errorf("dictionary type " + _type.String() + "not yet supported") // FIXME
		}
	default:
		return fmt.Errorf("dictionary encoding " + p.header.GetEncoding().String() + "not yet supported") // FIXME
	}

	return nil
}